diff --git a/kitty/boss.py b/kitty/boss.py index ffda0dae2..027ce6a47 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -15,7 +15,7 @@ from .conf.utils import to_cmdline from .config import initial_window_size_func, prepare_config_file_for_editing from .config_data import MINIMUM_FONT_SIZE from .constants import ( - appname, config_dir, set_boss, supports_primary_selection + appname, config_dir, kitty_exe, set_boss, supports_primary_selection ) from .fast_data_types import ( ChildMonitor, background_opacity_of, change_background_opacity, @@ -561,7 +561,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:])'] + get_editor() + [confpath] + cmd = [kitty_exe(), '+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): @@ -600,7 +600,7 @@ class Boss: copts = {k: self.opts[k] for k in ('select_by_word_characters', 'open_url_with')} overlay_window = tab.new_special_window( SpecialWindow( - ['kitty', '+runpy', 'from kittens.runner import main; main()'] + args, + [kitty_exe(), '+runpy', 'from kittens.runner import main; main()'] + args, stdin=data, env={ 'KITTY_COMMON_OPTS': json.dumps(copts), @@ -647,7 +647,7 @@ class Boss: break def kitty_shell(self, window_type): - cmd = ['kitty', '@'] + cmd = [kitty_exe(), '@'] if window_type == 'tab': window = self._new_tab(cmd).active_window elif window_type == 'os_window': diff --git a/kitty/constants.py b/kitty/constants.py index 587e78dee..e35ef11bd 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -21,6 +21,22 @@ ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy') WindowGeometry = namedtuple('WindowGeometry', 'left top right bottom xnum ynum') +def kitty_exe(): + ans = getattr(kitty_exe, 'ans', None) + if ans is None: + rpath = getattr(sys, 'bundle_exe_dir', None) + items = frozenset(os.environ['PATH'].split(os.pathsep)) + if not rpath: + for candidate in items: + if os.access(os.path.join(candidate, 'kitty'), os.X_OK): + rpath = candidate + break + else: + rpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'launcher') + ans = kitty_exe.ans = os.path.join(rpath, 'kitty') + return ans + + def _get_config_dir(): if 'KITTY_CONFIG_DIRECTORY' in os.environ: return os.path.abspath(os.path.expanduser(os.environ['KITTY_CONFIG_DIRECTORY'])) diff --git a/kitty/main.py b/kitty/main.py index a3eb6a2a9..5fe738ab9 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -12,7 +12,8 @@ from .boss import Boss from .cli import create_opts, parse_args from .config import cached_values_for, initial_window_size_func from .constants import ( - appname, config_dir, glfw_path, is_macos, is_wayland, logo_data_file + appname, config_dir, glfw_path, is_macos, is_wayland, kitty_exe, + logo_data_file ) from .fast_data_types import ( GLFW_MOD_SUPER, create_os_window, free_font_data, glfw_init, @@ -199,14 +200,8 @@ def _main(): print('Failed to set locale with no LANG, ignoring', file=sys.stderr) # Ensure kitty is in PATH - rpath = getattr(sys, 'bundle_exe_dir', None) + rpath = os.path.dirname(kitty_exe()) items = frozenset(os.environ['PATH'].split(os.pathsep)) - if not rpath: - for candidate in items: - if os.access(os.path.join(candidate, 'kitty'), os.X_OK): - break - else: - rpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'launcher') if rpath and rpath not in items: os.environ['PATH'] += os.pathsep + rpath diff --git a/kitty/session.py b/kitty/session.py index f0ae2cb03..84a442e66 100644 --- a/kitty/session.py +++ b/kitty/session.py @@ -5,7 +5,7 @@ import shlex from .config_data import to_layout_names -from .constants import shell_path +from .constants import shell_path, kitty_exe from .layout import all_layouts from .utils import log_error @@ -125,7 +125,7 @@ def create_session(opts, args=None, special_window=None, cwd_from=None, respect_ if special_window is None: cmd = args.args if args and args.args else resolved_shell(opts) if args.hold: - cmd = ['kitty', '+hold'] + cmd + cmd = [kitty_exe(), '+hold'] + cmd from kitty.tabs import SpecialWindow k = {'cwd_from': cwd_from} if respect_cwd: