diff --git a/kitty/main.py b/kitty/main.py index a6fc26dcf..5a5c3af40 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -226,7 +226,18 @@ def setup_environment(opts, args): if 'EDITOR' not in os.environ: shell_env = read_shell_environment(opts) if 'EDITOR' in shell_env: - os.environ['EDITOR'] = shell_env['EDITOR'] + editor = shell_env['EDITOR'] + if 'PATH' in shell_env: + import shlex + editor_cmd = shlex.split(editor) + if not os.path.isabs(editor_cmd[0]): + editor_cmd[0] = shutil.which(editor_cmd[0], path=shell_env['PATH']) + if editor_cmd[0]: + editor = ' '.join(map(shlex.quote, editor_cmd)) + else: + editor = None + if editor: + os.environ['EDITOR'] = editor else: os.environ['EDITOR'] = opts.editor if args.listen_on: