Allow enabling remote control in only some kitty windows

This commit is contained in:
Kovid Goyal 2018-08-06 20:04:12 +05:30
parent 9235d2b8e4
commit b6a5d09d4f
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
6 changed files with 37 additions and 11 deletions

View file

@ -26,7 +26,9 @@ Changelog
- Remote control: Allow matching windows by the environment variables of their
child process as well
- Allow running kitten via the remote control system (:iss:`738`)
- Allow running kittens via the remote control system (:iss:`738`)
- Allow enabling remote control in only some kitty windows
- Add a keyboard shortcut to reset the terminal (:sc:`reset_terminal`). It
takes parameters so you can define your own shortcuts to clear the

View file

@ -119,4 +119,20 @@ keyboard shortcut (:sc:`kitty_shell` by default). This has the added
advantage that you dont need to use ``allow_remote_control`` to make it work.
Allowing only some windows to control kitty
----------------------------------------------
If you do not want to allow all programs running in |kitty| to control it, you can selectively
enable remote control for only some |kitty| windows. Simply create a shortcut
such as::
map ctrl+k new_window @ some_program
Then programs running in windows created with that shortcut can use ``kitty @``
to control kitty. Note that any program with the right level of permissions can
still write to the pipes of any other program on the same computer and
therefore can control |kitty|. It can, however, be useful to block programs
running on other computers (for example, over ssh) or as other users.
.. include:: generated/cli-kitty-at.rst

View file

@ -686,23 +686,19 @@ def do_set_tab_title(self, title, tab_id):
break
def kitty_shell(self, window_type):
cmd = [kitty_exe(), '@']
cmd = ['@', kitty_exe(), '@']
if window_type == 'tab':
window = self._new_tab(cmd).active_window
self._new_tab(cmd).active_window
elif window_type == 'os_window':
os_window_id = self._new_os_window(cmd)
window = self.os_window_map[os_window_id].active_window
self.os_window_map[os_window_id].active_window
elif window_type == 'overlay':
w = self.active_window
tab = self.active_tab
if w is not None and tab is not None and w.overlay_for is None:
window = tab.new_special_window(SpecialWindow(cmd, overlay_for=w.id))
else:
window = None
tab.new_special_window(SpecialWindow(cmd, overlay_for=w.id))
else:
window = self._new_window(cmd)
if window is not None:
window.allow_remote_control = True
self._new_window(cmd)
def switch_focus_to(self, window_idx):
tab = self.active_tab
@ -786,7 +782,7 @@ def data_for_at(arg):
if arg == '@ansi_screen':
return w.as_text(as_ansi=True)
if args[0].startswith('@'):
if args[0].startswith('@') and args[0] != '@':
stdin = data_for_at(args[0]) or None
if stdin is not None:
stdin = stdin.encode('utf-8')

View file

@ -79,6 +79,10 @@ class Child:
forked = False
def __init__(self, argv, cwd, opts, stdin=None, env=None, cwd_from=None):
self.allow_remote_control = False
if argv and argv[0] == '@':
self.allow_remote_control = True
argv = argv[1:]
self.argv = argv
if cwd_from is not None:
try:

View file

@ -815,6 +815,13 @@ def macos_titlebar_color(x):
working directory of the current window using::
map ctrl+alt+enter new_window_with_cwd
You can open a new window that is allowed to control kitty via
the kitty remote control facility by prefixing the command line with @.
Any programs running in that window will be allowed to control kitty.
For example::
map ctrl+enter new_window @ some_program
'''))
if is_macos:
k('new_os_window', 'cmd+n', 'new_os_window', _('New OS window'))

View file

@ -110,6 +110,7 @@ def __init__(self, tab, child, opts, args, override_title=None):
self.overlay_for = None
self.default_title = os.path.basename(child.argv[0] or appname)
self.child_title = self.default_title
self.allow_remote_control = child.allow_remote_control
self.id = add_window(tab.os_window_id, tab.id, self.title)
if not self.id:
raise Exception('No tab with id: {} in OS Window: {} was found, or the window counter wrapped'.format(tab.id, tab.os_window_id))