Allow using @selection in the launch cmdline

This commit is contained in:
Kovid Goyal 2019-11-13 10:46:04 +05:30
parent 059786ab66
commit ad2bd1bf63
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 2 deletions

View File

@ -249,7 +249,9 @@ def write_cli_docs(all_kitten_names):
f.write(option_spec_as_rst( f.write(option_spec_as_rst(
appname='launch', ospec=launch_options_spec, heading_char='_', appname='launch', ospec=launch_options_spec, heading_char='_',
message='''\ 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: with open('generated/cli-kitty.rst', 'w') as f:

View File

@ -896,6 +896,9 @@ class Boss:
stdin = stdin.encode('utf-8') stdin = stdin.encode('utf-8')
return env, stdin 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): def special_window_for_cmd(self, cmd, window=None, stdin=None, cwd_from=None, as_overlay=False):
w = window or self.active_window w = window or self.active_window
env, stdin = self.process_stdin_source(w, stdin) env, stdin = self.process_stdin_source(w, stdin)

View File

@ -164,7 +164,14 @@ def launch(boss, opts, args):
if opts.copy_cmdline and active_child: if opts.copy_cmdline and active_child:
cmd = active_child.foreground_cmdline cmd = active_child.foreground_cmdline
if cmd: 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: if opts.type == 'overlay' and active and not active.overlay_window_id:
kw['overlay_for'] = active.id kw['overlay_for'] = active.id
if opts.stdin_source: if opts.stdin_source: