Prefer VISUAL to EDITOR

Fix #2096
This commit is contained in:
toonn 2019-10-25 18:48:05 +02:00
parent 6634dc81fe
commit a64a0d64cb
3 changed files with 21 additions and 24 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=_(''' o('editor', '.', long_text=_('''
The console editor to use when editing the kitty config file or similar tasks. 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 A value of . means to use the environment variables VISUAL and EDITOR in that
environment variable has to be set not just in your shell startup scripts but order. Note that this environment variable has to be set not just in your shell
system-wide, otherwise kitty will not see it. startup scripts but system-wide, otherwise kitty will not see it.
''')) '''))
o('close_on_child_death', False, long_text=_(''' o('close_on_child_death', False, long_text=_('''

View File

@ -247,19 +247,19 @@ def read_shell_environment(opts=None):
def setup_environment(opts, args): def setup_environment(opts, args):
extra_env = opts.env.copy() extra_env = opts.env.copy()
if opts.editor == '.': if opts.editor == '.':
if 'EDITOR' not in os.environ: if 'VISUAL' not in os.environ and 'EDITOR' not in os.environ:
shell_env = read_shell_environment(opts) shell_env = read_shell_environment(opts)
if 'EDITOR' in shell_env: if 'VISUAL' in shell_env or 'EDITOR' in shell_env:
editor = shell_env['EDITOR'] for editor in (shell_env['VISUAL'], shell_env['EDITOR']):
if 'PATH' in shell_env: if 'PATH' in shell_env:
import shlex import shlex
editor_cmd = shlex.split(editor) editor_cmd = shlex.split(editor)
if not os.path.isabs(editor_cmd[0]): if not os.path.isabs(editor_cmd[0]):
editor_cmd[0] = shutil.which(editor_cmd[0], path=shell_env['PATH']) editor_cmd[0] = shutil.which(editor_cmd[0], path=shell_env['PATH'])
if editor_cmd[0]: if editor_cmd[0]:
editor = ' '.join(map(shlex.quote, editor_cmd)) editor = ' '.join(map(shlex.quote, editor_cmd))
else: else:
editor = None editor = None
if editor: if editor:
os.environ['EDITOR'] = editor os.environ['EDITOR'] = editor
else: else:

View File

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