Created
May 13, 2026 14:10
-
-
Save cinnamon-msft/1f52589615967a3118f64c2291532df6 to your computer and use it in GitHub Desktop.
Oh My Posh for GitHub Copilot CLI statusline - Catppuccin theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| rem Keep the wrapper tiny so Copilot can pass stdin straight through to PowerShell. | |
| pwsh -NoProfile -ExecutionPolicy Bypass -File "%~dp0statusline.ps1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", | |
| "version": 4, | |
| "final_space": false, | |
| "palette": { | |
| "text": "#494D64", | |
| "blue": "#8AADF4", | |
| "lavender": "#B7BDF8", | |
| "pink": "#F5BDE6", | |
| "green": "#A6DA95", | |
| "surface": "#6E738D", | |
| "white": "#FFFFFF" | |
| }, | |
| "blocks": [ | |
| { | |
| "type": "prompt", | |
| "alignment": "left", | |
| "segments": [ | |
| { | |
| "type": "text", | |
| "style": "diamond", | |
| "leading_diamond": "\ue0b6", | |
| "foreground": "p:text", | |
| "background": "p:pink", | |
| "template": " \uf07b {{ .Env.COPILOT_STATUS_FOLDER }}{{ if .Env.COPILOT_STATUS_BRANCH }} | \ue725 {{ .Env.COPILOT_STATUS_BRANCH }}{{ end }} " | |
| }, | |
| { | |
| "type": "text", | |
| "style": "powerline", | |
| "powerline_symbol": "\ue0b0", | |
| "foreground": "p:text", | |
| "background": "p:blue", | |
| "template": " {{ .Env.COPILOT_STATUS_TOKENS }} " | |
| }, | |
| { | |
| "type": "text", | |
| "style": "diamond", | |
| "trailing_diamond": "\ue0b4", | |
| "foreground": "p:white", | |
| "background": "p:surface", | |
| "template": "{{ if .Env.COPILOT_STATUS_CHANGES }} {{ .Env.COPILOT_STATUS_CHANGES }} {{ end }}" | |
| } | |
| ] | |
| } | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = 'Stop' | |
| [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new() | |
| function Format-TokenCount { | |
| param([Nullable[double]]$Value) | |
| if ($null -eq $Value) { return '?' } | |
| if ($Value -ge 1000000) { return ('{0:0.0}m' -f ($Value / 1000000)) } | |
| if ($Value -ge 1000) { return ('{0:0}k' -f ($Value / 1000)) } | |
| return ([int][Math]::Round($Value)).ToString() | |
| } | |
| # Copilot sends the statusline payload as JSON on stdin. | |
| $payload = [Console]::In.ReadToEnd() | |
| try { | |
| $json = $payload | ConvertFrom-Json | |
| } catch { | |
| Write-Host -NoNewline 'Copilot status unavailable' | |
| exit 0 | |
| } | |
| $context = $json.context_window | |
| $currentTokens = if ($null -ne $context.current_context_tokens) { | |
| [double]$context.current_context_tokens | |
| } else { | |
| $null | |
| } | |
| $contextLimit = if ($null -ne $context.displayed_context_limit) { | |
| [double]$context.displayed_context_limit | |
| } else { | |
| $null | |
| } | |
| $cost = $json.cost | |
| $linesAdded = if ($null -ne $cost.total_lines_added) { [int]$cost.total_lines_added } else { 0 } | |
| $linesRemoved = if ($null -ne $cost.total_lines_removed) { [int]$cost.total_lines_removed } else { 0 } | |
| $theme = Join-Path $PSScriptRoot 'statusline.omp.json' | |
| $cwd = if ($json.cwd) { [string]$json.cwd } else { (Get-Location).Path } | |
| $folderName = Split-Path -Path $cwd -Leaf | |
| if ([string]::IsNullOrWhiteSpace($folderName)) { | |
| $folderName = $cwd | |
| } | |
| $branchName = '' | |
| # Only show a branch when the payload cwd is actually inside a git work tree. | |
| $isRepo = & git -C $cwd rev-parse --is-inside-work-tree 2>$null | |
| if ($LASTEXITCODE -eq 0 -and $isRepo -eq 'true') { | |
| $branchName = (& git -C $cwd branch --show-current 2>$null).Trim() | |
| if ([string]::IsNullOrWhiteSpace($branchName)) { | |
| $branchName = (& git -C $cwd rev-parse --short HEAD 2>$null).Trim() | |
| } | |
| } | |
| $env:COPILOT_STATUS_FOLDER = $folderName | |
| $env:COPILOT_STATUS_BRANCH = $branchName | |
| $env:COPILOT_STATUS_TOKENS = "$(Format-TokenCount $currentTokens)/$(Format-TokenCount $contextLimit)" | |
| $env:COPILOT_STATUS_CHANGES = if ($linesAdded -or $linesRemoved) { "+$linesAdded/-$linesRemoved" } else { '' } | |
| try { | |
| # Let Oh My Posh draw the final line; the script only prepares the data. | |
| $output = & oh-my-posh print primary --config $theme --pwd $cwd --force --escape=false 2>$null | |
| if ([string]::IsNullOrWhiteSpace($output)) { | |
| throw 'Oh My Posh returned no output.' | |
| } | |
| Write-Host -NoNewline $output.TrimEnd() | |
| } catch { | |
| # Fallback stays readable if the theme cannot render for any reason. | |
| $branch = if ($env:COPILOT_STATUS_BRANCH) { " | $($env:COPILOT_STATUS_BRANCH)" } else { '' } | |
| $changes = if ($env:COPILOT_STATUS_CHANGES) { " | $($env:COPILOT_STATUS_CHANGES)" } else { '' } | |
| Write-Host -NoNewline "$($env:COPILOT_STATUS_FOLDER)$branch | $($env:COPILOT_STATUS_TOKENS)$changes" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment