hints kitten: Allow specifying :option:kitty +kitten hints --program multiple times to run multiple programs

See #1879
This commit is contained in:
Kovid Goyal 2019-08-02 10:03:04 +05:30
parent e4b0980d15
commit bdf7d98a36
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 24 additions and 17 deletions

View File

@ -10,6 +10,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
- hints kitten: Add a :option:`kitty +kitten hints --alphabet` option to
control what alphabets are used for hints (:iss:`1879`)
- hints kitten: Allow specifying :option:`kitty +kitten hints --program`
multiple times to run multiple programs (:iss:`1879`)
- Dont fail to start if running the shell to read the EDITOR env var fails
(:iss:`1869`)

View File

@ -252,7 +252,7 @@ def run_loop(args, text, all_marks, index_map):
handler = Hints(text, all_marks, index_map, args)
loop.loop(handler)
if handler.chosen and loop.return_code == 0:
return {'match': handler.chosen, 'program': args.program,
return {'match': handler.chosen, 'programs': args.program,
'multiple_joiner': args.multiple_joiner,
'type': args.type}
raise SystemExit(loop.return_code)
@ -339,10 +339,12 @@ def run(args, text):
# CLI {{{
OPTIONS = r'''
--program
default=default
type=list
What program to use to open matched text. Defaults to the default open program
for the operating system. Use a value of :file:`-` to paste the match into the
terminal window instead. A value of :file:`@` will copy the match to the clipboard.
A value of :file:`default` will run the default open program. Can be specified
multiple times to run multiple programs.
--type
@ -449,7 +451,7 @@ def main(args):
def handle_result(args, data, target_window_id, boss):
program = data['program']
programs = data['programs'] or ('default',)
matches = tuple(filter(None, data['match']))
joiner = data['multiple_joiner']
try:
@ -458,6 +460,7 @@ def handle_result(args, data, target_window_id, boss):
is_int = None
text_type = data['type']
@lru_cache()
def joined_text():
if is_int is not None:
try:
@ -473,20 +476,21 @@ def handle_result(args, data, target_window_id, boss):
q = {'newline': '\n\r', 'space': ' '}.get(joiner, '')
return q.join(matches)
if program == '-':
w = boss.window_id_map.get(target_window_id)
if w is not None:
w.paste(joined_text())
elif program == '@':
set_clipboard_string(joined_text())
else:
cwd = None
w = boss.window_id_map.get(target_window_id)
if w is not None:
cwd = w.cwd_of_child
program = None if program == 'default' else program
for m in matches:
boss.open_url(m, program, cwd=cwd)
for program in programs:
if program == '-':
w = boss.window_id_map.get(target_window_id)
if w is not None:
w.paste(joined_text())
elif program == '@':
set_clipboard_string(joined_text())
else:
cwd = None
w = boss.window_id_map.get(target_window_id)
if w is not None:
cwd = w.cwd_of_child
program = None if program == 'default' else program
for m in matches:
boss.open_url(m, program, cwd=cwd)
handle_result.type_of_input = 'screen'