Files
dotfiles/dot_config/kitty/window_titler.py
T
Prad NukalaandClaude Fable 5 3c691e8dc5 config(kitty,yazi,lazygit,lazydocker,gh): add universal tui tools from live home
kitty full config (theme symlink preserved, VictorMono NF). yazi opener
OS-branched via template (open vs xdg-open). yazi/lazygit refreshed to
live. lazydocker default empty config. gh config.yml as private_ —
hosts.yml excluded (oauth token).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-09 14:53:13 -04:00

98 lines
2.7 KiB
Python

# ~/.config/kitty/mywatcher.py
from kitty.tabs import TabManager
from typing import Any
from kitty.boss import Boss
from kitty.window import Window
# from pprint import pprint
# Kitty currently ships with Python 3.12, but os.ptsname was added in 3.13.
import ctypes
libc = ctypes.CDLL("libc.so.6")
libc.ptsname.restype = ctypes.c_char_p
updating = False
def get_title(window: Window, title: str) -> str:
vt = "n/a"
try:
vt = window.user_vars["vt"]
except KeyError:
pass
ptsname = libc.ptsname(window.child.child_fd).decode()
ptsname = ptsname.removeprefix("/dev/")
return f"{title} [{vt} {ptsname}]"
def on_title_change(boss: Boss, window: Window, data: dict[str, Any]) -> None:
# pprint(("title change", "window", window, "data", data))
tm = boss.active_tab_manager_with_dispatch
if tm is not None:
update_title(boss, window, tm)
def on_tab_bar_dirty(boss: Boss, window: Window, data: dict[str, Any]) -> None:
# called when any changes happen to the tab bar, such a new tabs being
# created, tab titles changing, tabs moving, etc. Useful to display the
# tab bar externally to kitty. This is called even if the tab bar is
# hidden. Note that this is called only in *global watchers*, that is
# watchers defined in kitty.conf or using the --watcher command line
# flag. data contains tab_manager which is the object responsible for
# managing all tabs in a single OS Window.
# return get_title(window, data["title"])
tm = data["tab_manager"]
update_title(boss, window, tm)
def update_title(boss: Boss, window: Window, tm: TabManager) -> None:
# pprint(("update title", "window", window))
global updating
if updating:
# pprint("already updating, skipping")
return
tab = tm.active_tab
if tab is None:
return
title = get_title(window, window.child_title)
if title != tab.effective_title:
updating = True
# pprint(
# (
# "title",
# title,
# "tab.effective title",
# tab.effective_title,
# "window.title",
# window.title,
# "window.child_title",
# window.child_title,
# )
# )
window.set_title(title)
updating = False
else:
pass
# pprint(
# (
# "no update",
# "title",
# title,
# "tab.effective title",
# tab.effective_title,
# "window.title",
# window.title,
# "window.child_title",
# window.child_title,
# )
# )
return