hints kitten: Perform copy action with --program when matching linenum
This commit is contained in:
parent
fccd776732
commit
4c9d90efbb
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user