From 634d262b645b09aea757dd75b1754b3243ce49d1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 4 Aug 2018 22:06:47 +0530 Subject: [PATCH] When using the --listen-on option have kitty @ automatically connect to the socket even when --to is not specified The listen on value is set in the env of the child processes, so kitty @ can read it when run from inside kitty. --- kitty/cli.py | 13 ++++++++----- kitty/main.py | 6 ++++-- kitty/remote_control.py | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/kitty/cli.py b/kitty/cli.py index 689ce1594..44dd62325 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -109,11 +109,14 @@ regardless of this option. --listen-on Tell kitty to listen on the specified address for control messages. For example, :option:`{appname} --listen-on`=unix:/tmp/mykitty or -:option:`{appname} --listen-on`=tcp:localhost:12345. On Linux systems, you can also use abstract -UNIX sockets, not associated with a file, like this: :option:`{appname} --listen-on`=unix:@mykitty. -To control kitty, you can send it commands with :italic:`kitty @` using the :option:`kitty @ --to` option -to specify this address. Note that this option will be ignored, unless you set -:opt:`allow_remote_control` to yes in :file:`kitty.conf`. +:option:`{appname} --listen-on`=tcp:localhost:12345. On Linux systems, you can +also use abstract UNIX sockets, not associated with a file, like this: +:option:`{appname} --listen-on`=unix:@mykitty. To control kitty, you can send +it commands with :italic:`kitty @` using the :option:`kitty @ --to` option to +specify this address. This option will be ignored, unless you set +:opt:`allow_remote_control` to yes in :file:`kitty.conf`. Note that if you run +:italic:`kitty @` within a kitty window, there is no need to specify the :italic:`--to` +option as it is read automatically from the environment. # Debugging options diff --git a/kitty/main.py b/kitty/main.py index da25a1035..84464339a 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -203,10 +203,12 @@ def macos_cmdline(): return ans -def setup_environment(opts): +def setup_environment(opts, args): extra_env = opts.env.copy() if opts.editor != '.': os.environ['EDITOR'] = opts.editor + if args.listen_on: + os.environ['KITTY_LISTEN_ON'] = args.listen_on set_default_env(extra_env) @@ -264,7 +266,7 @@ def _main(): return init_glfw(args.debug_keyboard) # needed for parsing native keysyms opts = create_opts(args) - setup_environment(opts) + setup_environment(opts, args) try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 0a877d8c6..5e4abafbb 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -3,6 +3,7 @@ # License: GPL v3 Copyright: 2018, Kovid Goyal import json +import os import re import sys import types @@ -164,6 +165,8 @@ def main(args): else: no_response = func.no_response send['no_response'] = no_response + if not global_opts.to and 'KITTY_LISTEN_ON' in os.environ: + global_opts.to = os.environ['KITTY_LISTEN_ON'] response = do_io(global_opts.to, send, no_response) if no_response: return