mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 19:21:38 +02:00
Add a few more special command line arguments for launch
Now all ``KITTY_PIPE_DATA`` is also available via command line argument substitution Fixes #3593
This commit is contained in:
@@ -18,6 +18,10 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
|||||||
- macOS: When the Apple Color Emoji font lacks an emoji glyph search for it in other
|
- macOS: When the Apple Color Emoji font lacks an emoji glyph search for it in other
|
||||||
installed fonts (:iss:`3591`)
|
installed fonts (:iss:`3591`)
|
||||||
|
|
||||||
|
- Add a few more special commandline arguments for the launch command. Now all
|
||||||
|
``KITTY_PIPE_DATA`` is also available via command line argument substitution
|
||||||
|
(:iss:`3593`)
|
||||||
|
|
||||||
|
|
||||||
0.20.3 [2021-05-06]
|
0.20.3 [2021-05-06]
|
||||||
----------------------
|
----------------------
|
||||||
|
|||||||
@@ -54,9 +54,34 @@ Special arguments
|
|||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
There are a few special placeholder arguments that can be specified as part of
|
There are a few special placeholder arguments that can be specified as part of
|
||||||
the command line. Namely ``@selection`` which is replaced by the current
|
the command line:
|
||||||
selection and ``@active-kitty-window-id`` which is replaced by the id of the
|
|
||||||
currently active kitty window. For example::
|
|
||||||
|
``@selection``
|
||||||
|
replaced by the currently selected text
|
||||||
|
|
||||||
|
``@active-kitty-window-id``
|
||||||
|
replaced by the id of the currently active kitty window
|
||||||
|
|
||||||
|
``@line-count``
|
||||||
|
replaced by the number of lines in STDIN. Only present when passing some
|
||||||
|
data to STDIN
|
||||||
|
|
||||||
|
``@input-line-number``
|
||||||
|
replaced the number of lines a pager should scroll to match the current
|
||||||
|
scroll position in kitty. See :opt:`scrollback_pager` for details
|
||||||
|
|
||||||
|
``@scrolled-by``
|
||||||
|
replaced by the number of lines kitty is currently scrolled by
|
||||||
|
|
||||||
|
``@cursor-x``
|
||||||
|
replaced by the current cursor x position
|
||||||
|
|
||||||
|
``@cursor-y``
|
||||||
|
replaced by the current cursor y position
|
||||||
|
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
map f1 launch my-program @active-kitty-window-id
|
map f1 launch my-program @active-kitty-window-id
|
||||||
|
|
||||||
|
|||||||
@@ -1160,7 +1160,10 @@ class Boss:
|
|||||||
|
|
||||||
prev_tab = previous_tab
|
prev_tab = previous_tab
|
||||||
|
|
||||||
def process_stdin_source(self, window: Optional[Window] = None, stdin: Optional[str] = None) -> Tuple[Optional[Dict[str, str]], Optional[bytes]]:
|
def process_stdin_source(
|
||||||
|
self, window: Optional[Window] = None,
|
||||||
|
stdin: Optional[str] = None, copy_pipe_data: Optional[Dict] = None
|
||||||
|
) -> Tuple[Optional[Dict[str, str]], Optional[bytes]]:
|
||||||
w = window or self.active_window
|
w = window or self.active_window
|
||||||
if not w:
|
if not w:
|
||||||
return None, None
|
return None, None
|
||||||
@@ -1174,6 +1177,8 @@ class Boss:
|
|||||||
if stdin is not None:
|
if stdin is not None:
|
||||||
pipe_data = w.pipe_data(stdin, has_wrap_markers=add_wrap_markers) if w else None
|
pipe_data = w.pipe_data(stdin, has_wrap_markers=add_wrap_markers) if w else None
|
||||||
if pipe_data:
|
if pipe_data:
|
||||||
|
if copy_pipe_data is not None:
|
||||||
|
copy_pipe_data.update(pipe_data)
|
||||||
env = {
|
env = {
|
||||||
'KITTY_PIPE_DATA':
|
'KITTY_PIPE_DATA':
|
||||||
'{scrolled_by}:{cursor_x},{cursor_y}:{lines},{columns}'.format(**pipe_data)
|
'{scrolled_by}:{cursor_x},{cursor_y}:{lines},{columns}'.format(**pipe_data)
|
||||||
|
|||||||
@@ -285,6 +285,20 @@ def launch(
|
|||||||
kw['location'] = opts.location
|
kw['location'] = opts.location
|
||||||
if opts.copy_colors and active:
|
if opts.copy_colors and active:
|
||||||
kw['copy_colors_from'] = active
|
kw['copy_colors_from'] = active
|
||||||
|
pipe_data: Dict[str, Any] = {}
|
||||||
|
if opts.stdin_source != 'none':
|
||||||
|
q = str(opts.stdin_source)
|
||||||
|
if opts.stdin_add_formatting:
|
||||||
|
if q in ('@screen', '@screen_scrollback', '@alternate', '@alternate_scrollback'):
|
||||||
|
q = '@ansi_' + q[1:]
|
||||||
|
if opts.stdin_add_line_wrap_markers:
|
||||||
|
q += '_wrap'
|
||||||
|
penv, stdin = boss.process_stdin_source(window=active, stdin=q, copy_pipe_data=pipe_data)
|
||||||
|
if stdin:
|
||||||
|
kw['stdin'] = stdin
|
||||||
|
if penv:
|
||||||
|
env.update(penv)
|
||||||
|
|
||||||
cmd = args or None
|
cmd = args or None
|
||||||
if opts.copy_cmdline and active_child:
|
if opts.copy_cmdline and active_child:
|
||||||
cmd = active_child.foreground_cmdline
|
cmd = active_child.foreground_cmdline
|
||||||
@@ -298,6 +312,21 @@ def launch(
|
|||||||
x = s
|
x = s
|
||||||
elif x == '@active-kitty-window-id':
|
elif x == '@active-kitty-window-id':
|
||||||
x = str(active.id)
|
x = str(active.id)
|
||||||
|
elif x == '@input-line-number':
|
||||||
|
if 'input_line_number' in pipe_data:
|
||||||
|
x = str(pipe_data['input_line_number'])
|
||||||
|
elif x == '@line-count':
|
||||||
|
if 'lines' in pipe_data:
|
||||||
|
x = str(pipe_data['lines'])
|
||||||
|
elif x in ('@cursor-x', '@cursor-y', '@scrolled-by'):
|
||||||
|
if active is not None:
|
||||||
|
screen = active.screen
|
||||||
|
if x == '@scrolled-by':
|
||||||
|
x = str(screen.scrolled_by)
|
||||||
|
elif x == '@cursor-x':
|
||||||
|
x = str(screen.cursor.x)
|
||||||
|
elif x == '@cursor-y':
|
||||||
|
x = str(screen.cursor.y)
|
||||||
final_cmd.append(x)
|
final_cmd.append(x)
|
||||||
exe = find_exe(final_cmd[0])
|
exe = find_exe(final_cmd[0])
|
||||||
if not exe:
|
if not exe:
|
||||||
@@ -310,19 +339,6 @@ def launch(
|
|||||||
kw['cmd'] = final_cmd
|
kw['cmd'] = final_cmd
|
||||||
if opts.type == 'overlay' and active:
|
if opts.type == 'overlay' and active:
|
||||||
kw['overlay_for'] = active.id
|
kw['overlay_for'] = active.id
|
||||||
if opts.stdin_source != 'none':
|
|
||||||
q = str(opts.stdin_source)
|
|
||||||
if opts.stdin_add_formatting:
|
|
||||||
if q in ('@screen', '@screen_scrollback', '@alternate', '@alternate_scrollback'):
|
|
||||||
q = '@ansi_' + q[1:]
|
|
||||||
if opts.stdin_add_line_wrap_markers:
|
|
||||||
q += '_wrap'
|
|
||||||
penv, stdin = boss.process_stdin_source(window=active, stdin=q)
|
|
||||||
if stdin:
|
|
||||||
kw['stdin'] = stdin
|
|
||||||
if penv:
|
|
||||||
env.update(penv)
|
|
||||||
|
|
||||||
if opts.type == 'background':
|
if opts.type == 'background':
|
||||||
cmd = kw['cmd']
|
cmd = kw['cmd']
|
||||||
if not cmd:
|
if not cmd:
|
||||||
|
|||||||
Reference in New Issue
Block a user