feat(tui): append git branch to cwd label in status bar

Adds useGitBranch hook (async, cached, 15s TTL) and fmtCwdBranch
helper so the footer shows `~/repo (main)` instead of just `~/repo`.
Degrades silently when git is unavailable or cwd is outside a repo.

Partial fix for #12267 (TUI portion; #12277 covers the Python side).
This commit is contained in:
Brooklyn Nicholson 2026-04-18 17:14:29 -05:00
parent 0175ff7516
commit ff2aa7ccd7
4 changed files with 160 additions and 3 deletions

View file

@ -4,3 +4,14 @@ export const shortCwd = (cwd: string, max = 28) => {
return p.length <= max ? p : `${p.slice(-(max - 1))}`
}
export const fmtCwdBranch = (cwd: string, branch: null | string, max = 40) => {
if (!branch) {
return shortCwd(cwd, max)
}
const b = branch.length > 16 ? `${branch.slice(-15)}` : branch
const tag = ` (${b})`
return `${shortCwd(cwd, Math.max(8, max - tag.length))}${tag}`
}