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
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 - hints kitten: Add a :option:`kitty +kitten hints --alphabet` option to
control what alphabets are used for hints (:iss:`1879`) 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 - Dont fail to start if running the shell to read the EDITOR env var fails
(:iss:`1869`) (: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) handler = Hints(text, all_marks, index_map, args)
loop.loop(handler) loop.loop(handler)
if handler.chosen and loop.return_code == 0: 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, 'multiple_joiner': args.multiple_joiner,
'type': args.type} 'type': args.type}
raise SystemExit(loop.return_code) raise SystemExit(loop.return_code)
@@ -339,10 +339,12 @@ def run(args, text):
# CLI {{{ # CLI {{{
OPTIONS = r''' OPTIONS = r'''
--program --program
default=default type=list
What program to use to open matched text. Defaults to the default open program 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 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. 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 --type
@@ -449,7 +451,7 @@ def main(args):
def handle_result(args, data, target_window_id, boss): def handle_result(args, data, target_window_id, boss):
program = data['program'] programs = data['programs'] or ('default',)
matches = tuple(filter(None, data['match'])) matches = tuple(filter(None, data['match']))
joiner = data['multiple_joiner'] joiner = data['multiple_joiner']
try: try:
@@ -458,6 +460,7 @@ def handle_result(args, data, target_window_id, boss):
is_int = None is_int = None
text_type = data['type'] text_type = data['type']
@lru_cache()
def joined_text(): def joined_text():
if is_int is not None: if is_int is not None:
try: try:
@@ -473,20 +476,21 @@ def handle_result(args, data, target_window_id, boss):
q = {'newline': '\n\r', 'space': ' '}.get(joiner, '') q = {'newline': '\n\r', 'space': ' '}.get(joiner, '')
return q.join(matches) return q.join(matches)
if program == '-': for program in programs:
w = boss.window_id_map.get(target_window_id) if program == '-':
if w is not None: w = boss.window_id_map.get(target_window_id)
w.paste(joined_text()) if w is not None:
elif program == '@': w.paste(joined_text())
set_clipboard_string(joined_text()) elif program == '@':
else: set_clipboard_string(joined_text())
cwd = None else:
w = boss.window_id_map.get(target_window_id) cwd = None
if w is not None: w = boss.window_id_map.get(target_window_id)
cwd = w.cwd_of_child if w is not None:
program = None if program == 'default' else program cwd = w.cwd_of_child
for m in matches: program = None if program == 'default' else program
boss.open_url(m, program, cwd=cwd) for m in matches:
boss.open_url(m, program, cwd=cwd)
handle_result.type_of_input = 'screen' handle_result.type_of_input = 'screen'