mirror of
https://github.com/prdlk/dotfiles.git
synced 2026-11-02 19:32:43 +00:00
feat(config): enhance kitty tab bar icons and multi-process detection
This commit is contained in:
1 parent
703730a4b4
commit
42025b3f4d
2 files changed
+35
-13
No files matched your search
Binary file not shown.
+35
-13
@@ -36,7 +36,7 @@ ICONS: dict[str, str] = {
|
|||||||
'helix': EDITOR,
|
'helix': EDITOR,
|
||||||
# agents / harnesses
|
# agents / harnesses
|
||||||
'claude': '\U000f06a9', # nf-md-robot
|
'claude': '\U000f06a9', # nf-md-robot
|
||||||
'omp': '\U000f09da', # nf-md-brain
|
'omp': '\uf2db', # nf-fa-microchip
|
||||||
'opencode': '\uf121', # nf-fa-code
|
'opencode': '\uf121', # nf-fa-code
|
||||||
'crush': '\uf0e7', # nf-fa-bolt
|
'crush': '\uf0e7', # nf-fa-bolt
|
||||||
'codex': '\uf120', # nf-fa-terminal
|
'codex': '\uf120', # nf-fa-terminal
|
||||||
@@ -53,7 +53,7 @@ ICONS: dict[str, str] = {
|
|||||||
'docker': '\uf308',
|
'docker': '\uf308',
|
||||||
'docker-compose': '\uf308',
|
'docker-compose': '\uf308',
|
||||||
'podman': '\uf308',
|
'podman': '\uf308',
|
||||||
'kubectl': '\ue7b2', # nf-dev-kubernetes
|
'kubectl': '\U000f10fe', # nf-md-kubernetes
|
||||||
# multiplexers / terminals-in-terminals
|
# multiplexers / terminals-in-terminals
|
||||||
'herdr': '\uf009', # nf-fa-th_large — panes
|
'herdr': '\uf009', # nf-fa-th_large — panes
|
||||||
'tmux': '\uf00a', # nf-fa-th
|
'tmux': '\uf00a', # nf-fa-th
|
||||||
@@ -113,7 +113,7 @@ _repo: dict[str, str] = {}
|
|||||||
|
|
||||||
def draw_title(data: dict[str, Any]) -> str:
|
def draw_title(data: dict[str, Any]) -> str:
|
||||||
tab = data['tab']
|
tab = data['tab']
|
||||||
program = _program(_cmdline(data['tab_id']), tab.active_exe)
|
program = _program(_cmdlines(data['tab_id']), tab.active_exe)
|
||||||
index = data['index']
|
index = data['index']
|
||||||
if program in EDITORS:
|
if program in EDITORS:
|
||||||
edited = _nvim_file(data['title'])
|
edited = _nvim_file(data['title'])
|
||||||
@@ -127,25 +127,47 @@ def draw_title(data: dict[str, Any]) -> str:
|
|||||||
return f'{index} {icon} {_elide(label or data["title"])}'
|
return f'{index} {icon} {_elide(label or data["title"])}'
|
||||||
|
|
||||||
|
|
||||||
def _cmdline(tab_id: int) -> list[str]:
|
def _cmdlines(tab_id: int) -> list[list[str]]:
|
||||||
"""argv of the tab's active window's foreground process, [] if unavailable."""
|
"""argv of every foreground process of the tab's active window.
|
||||||
|
|
||||||
|
All of them, not just `foreground_cmdline`: an editor commonly has LSP/agent
|
||||||
|
children in the same process group, and kitty's single "process for cwd" can
|
||||||
|
be either one of them.
|
||||||
|
"""
|
||||||
from kitty.boss import get_boss
|
from kitty.boss import get_boss
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tab = get_boss().tab_for_id(tab_id)
|
tab = get_boss().tab_for_id(tab_id)
|
||||||
window = tab.active_window if tab is not None else None
|
window = tab.active_window if tab is not None else None
|
||||||
return list(window.child.foreground_cmdline) if window is not None else []
|
if window is None:
|
||||||
|
return []
|
||||||
|
return [list(p['cmdline'] or ()) for p in window.child.foreground_processes]
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def _program(cmdline: list[str], fallback_exe: str) -> str:
|
def _program(cmdlines: list[list[str]], fallback_exe: str) -> str:
|
||||||
"""Program name a tab should be iconified by.
|
"""Program a tab should be iconified by, across its foreground processes.
|
||||||
|
|
||||||
Walks the cmdline past runners and flags: `node …/claude` is claude, an
|
An editor wins over anything else (nvim with a node LSP child is nvim), then
|
||||||
unknown script keeps its runtime's icon (`uv run python train.py` is
|
the first process with an icon, then whatever the first process is.
|
||||||
python, `bun run dev` is bun), and a bare `python` stays python. Falls back
|
"""
|
||||||
to kitty's own exe for the active window when the cmdline is unreadable.
|
names = [name for cmdline in cmdlines if (name := _resolve(cmdline))]
|
||||||
|
for name in names:
|
||||||
|
if name in EDITORS:
|
||||||
|
return name
|
||||||
|
for name in names:
|
||||||
|
if name in ICONS:
|
||||||
|
return name
|
||||||
|
return names[0] if names else _canonical(os.path.basename(fallback_exe or '').lower())
|
||||||
|
|
||||||
|
|
||||||
|
def _resolve(cmdline: list[str]) -> str:
|
||||||
|
"""Program name of one cmdline.
|
||||||
|
|
||||||
|
Walks past runners and flags: `node …/claude` is claude, an unknown script
|
||||||
|
keeps its runtime's icon (`uv run python train.py` is python, `bun run dev`
|
||||||
|
is bun), and a bare `python` stays python.
|
||||||
"""
|
"""
|
||||||
runtime = ''
|
runtime = ''
|
||||||
skipped = False
|
skipped = False
|
||||||
@@ -163,7 +185,7 @@ def _program(cmdline: list[str], fallback_exe: str) -> str:
|
|||||||
runtime = runtime or (name if name in ICONS else '')
|
runtime = runtime or (name if name in ICONS else '')
|
||||||
continue
|
continue
|
||||||
return name if name in ICONS or not runtime else runtime
|
return name if name in ICONS or not runtime else runtime
|
||||||
return runtime or _canonical(os.path.basename(fallback_exe or '').lower())
|
return runtime
|
||||||
|
|
||||||
|
|
||||||
def _canonical(name: str) -> str:
|
def _canonical(name: str) -> str:
|
||||||
|
|||||||
Reference in new issue
Block a user