From bdf7d98a36843e653e193bcd9297ac5d05c58169 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Aug 2019 10:03:04 +0530 Subject: [PATCH] hints kitten: Allow specifying :option:`kitty +kitten hints --program` multiple times to run multiple programs See #1879 --- docs/changelog.rst | 3 +++ kittens/hints/main.py | 38 +++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6a9ad818f..0666f9aa8 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -10,6 +10,9 @@ To update |kitty|, :doc:`follow the instructions `. - 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`) diff --git a/kittens/hints/main.py b/kittens/hints/main.py index f2dc47557..3ae3247a5 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -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'