From b6a5d09d4f2666eefe3b9b3b44469543dce6a20a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 6 Aug 2018 20:04:12 +0530 Subject: [PATCH] Allow enabling remote control in only some kitty windows --- docs/changelog.rst | 4 +++- docs/remote-control.rst | 16 ++++++++++++++++ kitty/boss.py | 16 ++++++---------- kitty/child.py | 4 ++++ kitty/config_data.py | 7 +++++++ kitty/window.py | 1 + 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 3ad510ebd..571d1bc78 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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 diff --git a/docs/remote-control.rst b/docs/remote-control.rst index ecb3fcd53..d640c2072 100644 --- a/docs/remote-control.rst +++ b/docs/remote-control.rst @@ -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 diff --git a/kitty/boss.py b/kitty/boss.py index 975660ca3..846d44ae1 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -686,23 +686,19 @@ class Boss: 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 @@ class Boss: 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') diff --git a/kitty/child.py b/kitty/child.py index 33469fe53..0819c376e 100644 --- a/kitty/child.py +++ b/kitty/child.py @@ -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: diff --git a/kitty/config_data.py b/kitty/config_data.py index 1b2f7e577..20c826f75 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -815,6 +815,13 @@ You can open a new window with the current working directory set to the 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')) diff --git a/kitty/window.py b/kitty/window.py index fa7f2346e..80c8a95fb 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -110,6 +110,7 @@ class Window: 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))