diff --git a/kitty/cmds.py b/kitty/cmds.py index 6e5a6eec7..857b03e79 100644 --- a/kitty/cmds.py +++ b/kitty/cmds.py @@ -384,7 +384,7 @@ def close_tab(boss, window, payload): 'Open new window', 'Open a new window in the specified tab. If you use the :option:`kitty @ new-window --match` option' ' the first matching tab is used. Otherwise the currently active tab is used.' - ' Prints out the id of the newly opened window. Any command line arguments' + ' Prints out the id of the newly opened window (unless :option:`--no-response` is used). Any command line arguments' ' are assumed to be the command line used to run in the new window, if none' ' are provided, the default shell is run. For example:\n' ':italic:`kitty @ new-window --title Email mutt`', @@ -416,13 +416,23 @@ Open a new tab --tab-title When using --new-tab set the title of the tab. + + +--no-response +type=bool-set +default=false +Dont wait for a response giving the id of the newly opened window. Note that +using this option means that you will not be notified of failures and that +the id of the new window will not be printed out. ''', argspec='[CMD ...]' ) def cmd_new_window(global_opts, opts, args): + if opts.no_response: + global_opts.no_command_response = True return {'match': opts.match, 'title': opts.title, 'cwd': opts.cwd, 'new_tab': opts.new_tab, 'tab_title': opts.tab_title, - 'window_type': opts.window_type, + 'window_type': opts.window_type, 'no_response': opts.no_response, 'keep_focus': opts.keep_focus, 'args': args or []} @@ -437,7 +447,7 @@ def new_window(boss, window, payload): wid = boss.active_window.id if payload['keep_focus'] and old_window: boss.set_active_window(old_window) - return str(wid) + return None if payload['no_response'] else str(wid) if payload['window_type'] == 'os': boss._new_os_window(w) @@ -446,7 +456,7 @@ def new_window(boss, window, payload): os_window_id = boss.set_active_window(old_window) if os_window_id: focus_os_window(os_window_id) - return str(wid) + return None if payload['no_response'] else str(wid) match = payload['match'] if match: @@ -459,7 +469,7 @@ def new_window(boss, window, payload): w = tab.new_special_window(w) if payload['keep_focus'] and old_window: boss.set_active_window(old_window) - return str(w.id) + return None if payload['no_response'] else str(w.id) # }}} diff --git a/kitty/remote_control.py b/kitty/remote_control.py index bc12f0d18..0a877d8c6 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -19,6 +19,8 @@ def handle_cmd(boss, window, cmd): cmd = json.loads(cmd) v = cmd['version'] if tuple(v)[:2] > version[:2]: + if cmd['no_response']: + return return {'ok': False, 'error': 'The kitty client you are using to send remote commands is newer than this kitty instance. This is not supported.'} c = cmap[cmd['cmd']] func = partial(c.impl(), boss, window) @@ -27,7 +29,7 @@ def handle_cmd(boss, window, cmd): response = {'ok': True} if ans is not None: response['data'] = ans - if not c.no_response: + if not c.no_response and not cmd['no_response']: return response @@ -137,6 +139,7 @@ def parse_rc_args(args): def main(args): global_opts, items = parse_rc_args(args) + global_opts.no_command_response = None if not items: from kitty.shell import main @@ -156,7 +159,14 @@ def main(args): } if payload is not None: send['payload'] = payload - response = do_io(global_opts.to, send, func.no_response) + if global_opts.no_command_response is not None: + no_response = global_opts.no_command_response + else: + no_response = func.no_response + send['no_response'] = no_response + response = do_io(global_opts.to, send, no_response) + if no_response: + return if not response.get('ok'): if response.get('tb'): print(response['tb'], file=sys.stderr)