[metadata] name = "kitty-days" description = """ Daily kitty sessions saved by ~/.config/kitty/day_session.py, last modified first. The preview lists each tab's windows (cwd, the program restored in it) with the tail of its saved scrollback. Enter opens the day in a new kitty. """ requirements = ["kitty", "python3", "mtime-sort"] # Entries are " week of tabs\t". [source] command = ''' for f in "$HOME"/.local/share/kitty-sessions/*/*.kitty-session; do [ -e "$f" ] || continue day=$(basename "$f" .kitty-session) printf '%s %s week of %s %s tabs\t%s\n' "$day" "$(date -d "$day" +%a)" \ "$(basename "$(dirname "$f")")" "$(grep -c '^new_tab' "$f")" "$f" done | mtime-sort ''' shell = "bash" display = "{split:\\t:0}" output = "{split:\\t:1}" # The script avoids braces: tv would read them as templates. [preview] command = ''' python3 - '{split:\t:1}' <<'PY' import json, os, shlex, sys FLAG = 'kitty-unserialize-data=' home = os.path.expanduser('~') tab, cwd = 0, '' for line in open(sys.argv[1]).read().splitlines(): word, _, rest = line.partition(' ') if word == 'new_tab': tab += 1 print('\x1b[1mtab %d\x1b[m' % tab) elif word == 'cd': cwd = shlex.split(rest)[0] elif word == 'launch': args = shlex.split(rest) data = json.loads(args.pop(0)[len(FLAG):]) if args and args[0].startswith(FLAG) else dict() wcwd = next((a.partition('=')[2] for a in args if a.startswith('--cwd=')), cwd) cmd = [a for a in args if not a.startswith('-')] # kitty writes every option as --opt=value dump, program = '', shlex.join(cmd) for step in data.get('cmd_at_shell_startup', '').split('; '): if step.startswith('cat '): dump = shlex.split(step)[1] elif step: program = step print(' \x1b[36m%s\x1b[m %s' % (wcwd.replace(home, '~', 1), program)) if dump and os.path.exists(dump): for l in open(dump, errors='replace').read().splitlines()[-6:]: print(' ' + l + '\x1b[m') PY ''' shell = "bash" # ctrl-e (edit) is bound globally in config.toml. [keybindings] enter = "actions:open" # Today's file, while no running kitty owns it, comes back as the live day # (saved again); any other day is a read-only snapshot. [actions.open] description = "Open the day in a new kitty" command = "setsid -f kitty --session '{split:\\t:1}' >/dev/null 2>&1" shell = "bash" mode = "execute" [actions.edit] description = "Open the session file in nvim" command = "nvim '{split:\\t:1}' /dev/tty" shell = "bash" mode = "execute"