From 4c9d90efbb324a576234d8910f3a814d6ee0ed82 Mon Sep 17 00:00:00 2001 From: pagedown Date: Thu, 2 Mar 2023 10:30:17 +0800 Subject: [PATCH] hints kitten: Perform copy action with --program when matching linenum --- kittens/hints/main.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 4bb338d83..b296dd3b5 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -595,7 +595,7 @@ example: :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 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 @@ -749,17 +749,24 @@ def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_i if action == 'self': if w is not None: - is_copy_action = cmd[0] in ('-', '@', '*') or cmd[0].startswith('@') - if is_copy_action: - text = ' '.join(cmd[1:]) - if cmd[0] == '-': - w.paste_bytes(text) - elif cmd[0] == '@': - set_clipboard_string(text) - elif cmd[0] == '*': - set_primary_selection(text) - elif cmd[0].startswith('@'): - boss.set_clipboard_buffer(cmd[0][1:], text) + def is_copy_action(s: str) -> bool: + return s in ('-', '@', '*') or s.startswith('@') + + 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) + elif program == '@': + set_clipboard_string(text) + elif program == '*': + set_primary_selection(text) + elif program.startswith('@'): + boss.set_clipboard_buffer(program[1:], text) else: import shlex text = ' '.join(shlex.quote(arg) for arg in cmd)