hints kitten: Perform copy action with --program when matching linenum

This commit is contained in:
pagedown 2023-03-02 10:30:17 +08:00
parent fccd776732
commit 4c9d90efbb
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB

View File

@ -595,7 +595,7 @@ example:
:code:`kitty +kitten hints --type=linenum --linenum-action=tab vim +{line} {path}` :code:`kitty +kitten hints --type=linenum --linenum-action=tab vim +{line} {path}`
will open the matched path at the matched line number in vim in will open the matched path at the matched line number in vim in
a new kitty tab. Note that in order to use :option:`--program` to copy or paste a new kitty tab. Note that in order to use :option:`--program` to copy or paste
text, you need to use the special value :code:`self`. the provided arguments, you need to use the special value :code:`self`.
--url-prefixes --url-prefixes
@ -749,17 +749,24 @@ def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_i
if action == 'self': if action == 'self':
if w is not None: if w is not None:
is_copy_action = cmd[0] in ('-', '@', '*') or cmd[0].startswith('@') def is_copy_action(s: str) -> bool:
if is_copy_action: return s in ('-', '@', '*') or s.startswith('@')
text = ' '.join(cmd[1:])
if cmd[0] == '-': programs = list(filter(is_copy_action, data['programs'] or ()))
# keep for backward compatibility, previously option `--program` does not need to be specified to perform copy actions
if is_copy_action(cmd[0]):
programs.append(cmd.pop(0))
if programs:
text = ' '.join(cmd)
for program in programs:
if program == '-':
w.paste_bytes(text) w.paste_bytes(text)
elif cmd[0] == '@': elif program == '@':
set_clipboard_string(text) set_clipboard_string(text)
elif cmd[0] == '*': elif program == '*':
set_primary_selection(text) set_primary_selection(text)
elif cmd[0].startswith('@'): elif program.startswith('@'):
boss.set_clipboard_buffer(cmd[0][1:], text) boss.set_clipboard_buffer(program[1:], text)
else: else:
import shlex import shlex
text = ' '.join(shlex.quote(arg) for arg in cmd) text = ' '.join(shlex.quote(arg) for arg in cmd)