From ad2bd1bf630aeb879f9bd68c5b8787e9d1d5adf6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 13 Nov 2019 10:46:04 +0530 Subject: [PATCH] Allow using @selection in the launch cmdline --- docs/conf.py | 4 +++- kitty/boss.py | 3 +++ kitty/launch.py | 9 ++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 95e67b44c..c0d20060d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -249,7 +249,9 @@ def write_cli_docs(all_kitten_names): f.write(option_spec_as_rst( appname='launch', ospec=launch_options_spec, heading_char='_', message='''\ -Launch an arbitrary program in a new kitty window/tab +Launch an arbitrary program in a new kitty window/tab. Note that +if you specify a program-to-run you can use the special placeholder +:code:`@selection` which will be replaced by the current selection. ''' )) with open('generated/cli-kitty.rst', 'w') as f: diff --git a/kitty/boss.py b/kitty/boss.py index 026b9aa0f..a9ad7cabe 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -896,6 +896,9 @@ class Boss: stdin = stdin.encode('utf-8') return env, stdin + def data_for_at(self, which, window=None, add_wrap_markers=False): + return data_for_at(window or self.active_window, which, add_wrap_markers=add_wrap_markers) + def special_window_for_cmd(self, cmd, window=None, stdin=None, cwd_from=None, as_overlay=False): w = window or self.active_window env, stdin = self.process_stdin_source(w, stdin) diff --git a/kitty/launch.py b/kitty/launch.py index c47566b66..c75848086 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -164,7 +164,14 @@ def launch(boss, opts, args): if opts.copy_cmdline and active_child: cmd = active_child.foreground_cmdline if cmd: - kw['cmd'] = cmd + final_cmd = [] + for x in cmd: + if x == '@selection' and active and not opts.copy_cmdline: + s = boss.data_for_at(active, x) + if s: + x = s + final_cmd.append(x) + kw['cmd'] = final_cmd if opts.type == 'overlay' and active and not active.overlay_window_id: kw['overlay_for'] = active.id if opts.stdin_source: