Add a config option to set the EDITOR kitty uses

Useful on systems that make it hard to set system-wide environment
variables. See #580
This commit is contained in:
Kovid Goyal
2018-05-28 12:24:09 +05:30
parent 20611c7c15
commit 345b3437f4
6 changed files with 20 additions and 7 deletions

View File

@@ -9,7 +9,8 @@ from functools import lru_cache
from gettext import gettext as _
from kitty.config import cached_values_for
from kitty.constants import config_dir, editor
from kitty.constants import config_dir
from kitty.utils import get_editor
from kitty.fast_data_types import wcswidth
from kitty.key_encoding import (
DOWN, ESCAPE, F1, F2, F3, F4, F12, LEFT, RELEASE, RIGHT, SHIFT, TAB, UP,
@@ -426,7 +427,7 @@ class UnicodeInput(Handler):
with open(favorites_path, 'wb') as f:
f.write(serialize_favorites(load_favorites()).encode('utf-8'))
with self.suspend():
p = subprocess.Popen(editor + [favorites_path])
p = subprocess.Popen(get_editor() + [favorites_path])
if p.wait() == 0:
load_favorites(refresh=True)
self.init_terminal_state()

View File

@@ -17,7 +17,7 @@ from .config import (
)
from .config_utils import to_cmdline
from .constants import (
appname, config_dir, editor, set_boss, supports_primary_selection
appname, config_dir, set_boss, supports_primary_selection
)
from .fast_data_types import (
ChildMonitor, background_opacity_of, change_background_opacity,
@@ -32,7 +32,7 @@ from .rgb import Color, color_from_int
from .session import create_session
from .tabs import SpecialWindow, SpecialWindowInstance, TabManager
from .utils import (
get_primary_selection, log_error, open_url, parse_address_spec,
get_editor, get_primary_selection, log_error, open_url, parse_address_spec,
remove_socket_file, safe_print, set_primary_selection, single_instance,
startup_notification_handler
)
@@ -538,7 +538,7 @@ class Boss:
confpath = prepare_config_file_for_editing()
# On macOS vim fails to handle SIGWINCH if it occurs early, so add a
# small delay.
cmd = ['kitty', '+runpy', 'import os, sys, time; time.sleep(0.05); os.execvp(sys.argv[1], sys.argv[1:])'] + editor + [confpath]
cmd = ['kitty', '+runpy', 'import os, sys, time; time.sleep(0.05); os.execvp(sys.argv[1], sys.argv[1:])'] + get_editor() + [confpath]
self.new_os_window(*cmd)
def get_output(self, source_window, num_lines=1):

View File

@@ -4,7 +4,6 @@
import os
import pwd
import shlex
import sys
from collections import namedtuple
@@ -16,7 +15,6 @@ str_version = '.'.join(map(str, version))
_plat = sys.platform.lower()
is_macos = 'darwin' in _plat
base = os.path.dirname(os.path.abspath(__file__))
editor = shlex.split(os.environ.get('EDITOR', 'vim'))
ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy')

View File

@@ -314,6 +314,13 @@ color15 #ffffff
# ensure that the shell starts in interactive mode and reads its startup rc files.
shell .
# 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.
editor .
#
# Close the window when the child process (shell) exits. If no (the default),
# the terminal will remain open when the child exits as long as there are still
# processes outputting to the terminal (for example disowned or backgrounded

View File

@@ -175,6 +175,8 @@ def _main():
single_instance.socket.sendall(data)
return
opts = create_opts(args)
if opts.editor != '.':
os.environ['EDITOR'] = opts.editor
init_graphics()
try:
with setup_profiling(args):

View File

@@ -392,3 +392,8 @@ def read_with_timeout(more_needed, timeout=10, src=sys.stdin.buffer):
break
else:
break
def get_editor():
import shlex
return shlex.split(os.environ.get('EDITOR', 'vim'))