Running help without arguments in the kitty shell now opens a categorized, searchable reference in a left dock instead of a pager. The new kitten collects the effective bindings and hands them to the palette in read-only mode.
48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
#!/usr/bin/env python
|
|
# License: GPLv3 Copyright: 2026, FWS
|
|
|
|
# The keybindings live in the Python options object, while the searchable list
|
|
# UI lives in the Go command palette. Collect the data here, then replace this
|
|
# process with the palette reading the same terminal, so the panel can run in a
|
|
# dock without a second protocol between the two.
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
from contextlib import suppress
|
|
|
|
help_text = 'Browse all keyboard shortcuts in a searchable panel'
|
|
usage = ''
|
|
OPTIONS = r"""
|
|
""".format
|
|
|
|
|
|
def main(args: list[str]) -> None:
|
|
from kittens.command_palette.main import collect_keys_data
|
|
from kitty.config import load_config
|
|
from kitty.constants import config_dir, kitten_exe
|
|
|
|
conf = os.path.join(config_dir, 'kitty.conf')
|
|
opts = load_config(conf) if os.path.exists(conf) else load_config()
|
|
fd, path = tempfile.mkstemp(prefix='kitty-shortcuts-', suffix='.json')
|
|
try:
|
|
with os.fdopen(fd, 'w', encoding='utf-8') as f:
|
|
json.dump(collect_keys_data(opts), f)
|
|
exe = kitten_exe()
|
|
os.execv(exe, [exe, 'command-palette', '--data-file=' + path, '--read-only'])
|
|
finally:
|
|
# execv only returns on failure; on success the Go side removes the file.
|
|
with suppress(OSError):
|
|
os.unlink(path)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv)
|
|
elif __name__ == '__doc__':
|
|
cd = sys.cli_docs # type: ignore
|
|
cd['usage'] = usage
|
|
cd['options'] = OPTIONS
|
|
cd['help_text'] = help_text
|
|
cd['short_desc'] = 'Browse all keyboard shortcuts in a searchable panel'
|