Update kitty keymaps

This commit is contained in:
rydesun 2023-05-19 19:43:39 +08:00
parent 3b4cc5aa6f
commit 1805b3527e
3 changed files with 127 additions and 16 deletions

View file

@ -2,14 +2,13 @@
include themes/everforest.conf
font_size 10
background_opacity 0.95
tab_bar_edge top
# 关闭响铃声音
enable_audio_bell no
# 不在系统窗口上报警
window_alert_on_bell no
# 下划线位置
# 下划线位置(偏下)
modify_font underline_position 100
# Unicode PUA使用Nerd font会覆盖来自其他字体的字形
@ -17,7 +16,7 @@ symbol_map U+E000-U+F8FF Symbols Nerd Font
# }}}
# {{{ Scrollback
# 可回滚的行数,原始值为2000
# 可回滚的行数,默认值为2000
scrollback_lines 20000
# 使用nvim作为pager需要搭配neovim配置
@ -26,33 +25,38 @@ scrollback_pager sh -c "exec nvim 63<&0 </dev/null --cmd 'let termcat=63'"
# }}}
# {{{ 按键
### ctrl+shift组可连续击键
map ctrl+shift+f scroll_page_down
map ctrl+shift+b scroll_page_up
# 查看所有按键
map kitty_mod+f2 kitten scripts/list_keys.py
### ctrl+t组窗口和标签
map ctrl+t>ctrl+d detach_window ask
### ctrl+shift组滚屏(可连续击键)
map kitty_mod+f scroll_page_down
map kitty_mod+b scroll_page_up
### ctrl+g组hints
### ctrl+t组标签页和窗口
map ctrl+t>ctrl+n new_tab
map ctrl+t>ctrl+d detach_tab
map ctrl+t>ctrl+m detach_tab ask
### ctrl+g组按hints操作文本
kitten_alias hints hints --alphabet ;ajfkdlshgqweruiopzxcvnmtby1230[
# 插入
#### 插入
map ctrl+g>ctrl+w kitten hints --type=word --program -
map ctrl+g>ctrl+l kitten hints --type=line --program -
# 复制
#### 复制
map ctrl+g>w kitten hints --type=word --program @
map ctrl+g>l kitten hints --type=line --program @
map ctrl+g>u kitten hints --type=url --program @
# 打开hyperlink (受open-actions.conf控制)
#### 打开hyperlink (受open-actions.conf控制)
map ctrl+g>ctrl+o kitten hints --type=hyperlink
# 打开URL文本
#### 打开URL文本
map ctrl+g>ctrl+u kitten hints --type=url
# NOTE: hyperlink和URL文本是不同的东西
#### NOTE: hyperlink和URL文本是不同的东西
# 用goldendict查询单词
map ctrl+g>ctrl+t kitten hints --type=word --program goldendict
#### 用goldendict查询单词
map ctrl+g>ctrl+q kitten hints --type=word --program goldendict
# 其他hints使用默认的快捷键ctrl+shift+p和ctrl+shift+e
# }}}

View file

@ -0,0 +1,105 @@
#!/usr/bin/env python3
"""Kitten to print the current list of keyboard shortcuts (consists of BOTH single keys and key
sequences).
https://github.com/kovidgoyal/kitty/issues/2164#issuecomment-1501097471
"""
import re
from collections import defaultdict
from typing import Optional, Union, Final
from kittens.tui.handler import result_handler
from kitty import fast_data_types
from kitty.boss import Boss
from kitty.options.utils import KeyMap, MouseEvent, SequenceMap
from kitty.tab_bar import Formatter as fmt
from kitty.types import Shortcut, mod_to_names
# List of categories and regular expressions to match actions on
categories: Final = {
"Scrollback": r"(^scroll_|show_scrollback|.*show.*_command_output)",
"Tab Management": r"(^|_)tab( |_|$)",
"Window Management": r"(^|_)windows?(_|$)",
"Layout Management": r"(^|_)layout(_|\b)",
"Hints": r"(_|\b)hints\b",
"Clipboard": r"(_to|_from|paste)_(clipboard|selection)",
"Options": r"^(set_|toggle_|change_)",
"Mouse Click": r"mouse_handle_click",
"Mouse Selection": r"mouse_selection",
"Other Shortcuts": r".",
}
ShortcutRepr = str
ActionMap = dict[str, list[ShortcutRepr]]
def main(args: list[str]) -> Optional[str]:
pass
@result_handler(no_ui=True)
def handle_result(args: list[str], answer: str, target_window_id: int, boss: Boss):
if boss.active_window is None:
return
opts = fast_data_types.get_options()
# set up keymaps (single keystrokes)
_keymap: KeyMap = (
boss.keymap
) # same as `opts.keymap`, except with global keymaps removed
keymap: dict[Union[Shortcut, MouseEvent], str] = {
Shortcut((key,)): action for key, action in _keymap.items()
}
# set up key sequences (combinations of keystrokes, separated by '>')
_seq_keymap: SequenceMap = opts.sequence_map
seq_keymap: dict[Shortcut, str] = {
Shortcut((key, *subseq_keys)): action
for key, subseq in _seq_keymap.items()
for subseq_keys, action in subseq.items()
}
keymap.update(seq_keymap.items())
# and mousemap
mousemap: dict[MouseEvent, str] = opts.mousemap
keymap.update(mousemap.items())
# categorize shortcuts
# because each action can have multiple shortcuts associated with it, we also attempt to
# group shortcuts with the same actions together.
output_categorized: dict[str, ActionMap] = defaultdict(lambda: defaultdict(list))
for key, action in keymap.items():
key_repr: ShortcutRepr = key.human_repr(kitty_mod=opts.kitty_mod)
key_repr = f"{key_repr:<15} {fmt.fg.red}{fmt.fg.default} {action}"
for subheader, re_pat in categories.items():
if re.search(re_pat, action):
action_map: ActionMap = output_categorized[subheader]
action_map[action].append(key_repr)
break
else:
emsg = f"No valid subheader found for keymap {key_repr!r}."
raise ValueError(emsg)
# print out shortcuts
output = [
"Kitty keyboard mappings",
"=======================",
"",
"My kitty_mod is {}.".format("+".join(mod_to_names(opts.kitty_mod))),
"",
]
for category in categories:
if category not in output_categorized:
continue
output.extend([category, "=" * len(category), ""])
output.extend(sum(output_categorized[category].values(), []))
output.append("")
boss.display_scrollback(
boss.active_window,
"\n".join(output),
title="Kitty keyboard mappings",
report_cursor=False,
)

View file

@ -0,0 +1,2 @@
[tool.pyright]
extraPaths = ["/usr/lib/kitty"]