Oh My Posh for GitHub Copilot CLI statusline - Catppuccin theme A developer created a PowerShell script that integrates GitHub Copilot's CLI statusline with Oh My Posh, using a Catppuccin theme. The script parses JSON payloads from Copilot to display real-time token usage, context window limits, and line changes, then passes the data to Oh My Posh for rendering. It includes fallback logic to show a plain text status if the theme fails to load. | $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" | | } |