This commit is contained in:
Kovid Goyal 2019-10-26 09:10:15 +05:30
commit 54ca775006
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 31 additions and 26 deletions

View File

@ -812,9 +812,9 @@ ensure that the shell starts in interactive mode and reads its startup rc files.
o('editor', '.', long_text=_('''
The console editor to use when editing the kitty config file or similar tasks.
A value of . means to use the environment variable EDITOR. Note that this
environment variable has to be set not just in your shell startup scripts but
system-wide, otherwise kitty will not see it.
A value of . means to use the environment variables VISUAL and EDITOR in that
order. Note that this environment variable has to be set not just in your shell
startup scripts but system-wide, otherwise kitty will not see it.
'''))
o('close_on_child_death', False, long_text=_('''

View File

@ -244,24 +244,32 @@ def read_shell_environment(opts=None):
return read_shell_environment.ans
def get_editor_from_env(shell_env):
for var in ('VISUAL', 'EDITOR'):
editor = shell_env.get(var)
if 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:
return editor
def setup_environment(opts, args):
extra_env = opts.env.copy()
if opts.editor == '.':
if 'EDITOR' not in os.environ:
editor = get_editor_from_env(os.environ)
if not editor:
shell_env = read_shell_environment(opts)
if 'EDITOR' in shell_env:
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
editor = get_editor_from_env(shell_env)
if editor:
os.environ['EDITOR'] = editor
else:
os.environ['EDITOR'] = opts.editor
if args.listen_on:

View File

@ -415,15 +415,12 @@ def get_editor():
ans = getattr(get_editor, 'ans', False)
if ans is False:
import shlex
ans = os.environ.get('EDITOR')
if not ans or not exe_exists(shlex.split(ans)[0]):
for q in ('vim', 'nvim', 'vi', 'emacs', 'kak', 'micro', 'nano', 'vis'):
r = exe_exists(q)
if r:
ans = r
break
else:
ans = 'vim'
for ans in (os.environ.get('VISUAL'), os.environ.get('EDITOR'), 'vim',
'nvim', 'vi', 'emacs', 'kak', 'micro', 'nano', 'vis'):
if ans and exe_exists(shlex.split(ans)[0]):
break
else:
ans = 'vim'
ans = shlex.split(ans)
get_editor.ans = ans
return ans