mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
When running kitty from within kitty, use a full path
Fixes inability to run kitty from the shell when the users shell scripts reset PATH. See #668
This commit is contained in:
@@ -15,7 +15,7 @@ from .conf.utils import to_cmdline
|
|||||||
from .config import initial_window_size_func, prepare_config_file_for_editing
|
from .config import initial_window_size_func, prepare_config_file_for_editing
|
||||||
from .config_data import MINIMUM_FONT_SIZE
|
from .config_data import MINIMUM_FONT_SIZE
|
||||||
from .constants import (
|
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 (
|
from .fast_data_types import (
|
||||||
ChildMonitor, background_opacity_of, change_background_opacity,
|
ChildMonitor, background_opacity_of, change_background_opacity,
|
||||||
@@ -561,7 +561,7 @@ class Boss:
|
|||||||
confpath = prepare_config_file_for_editing()
|
confpath = prepare_config_file_for_editing()
|
||||||
# On macOS vim fails to handle SIGWINCH if it occurs early, so add a
|
# On macOS vim fails to handle SIGWINCH if it occurs early, so add a
|
||||||
# small delay.
|
# 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)
|
self.new_os_window(*cmd)
|
||||||
|
|
||||||
def get_output(self, source_window, num_lines=1):
|
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')}
|
copts = {k: self.opts[k] for k in ('select_by_word_characters', 'open_url_with')}
|
||||||
overlay_window = tab.new_special_window(
|
overlay_window = tab.new_special_window(
|
||||||
SpecialWindow(
|
SpecialWindow(
|
||||||
['kitty', '+runpy', 'from kittens.runner import main; main()'] + args,
|
[kitty_exe(), '+runpy', 'from kittens.runner import main; main()'] + args,
|
||||||
stdin=data,
|
stdin=data,
|
||||||
env={
|
env={
|
||||||
'KITTY_COMMON_OPTS': json.dumps(copts),
|
'KITTY_COMMON_OPTS': json.dumps(copts),
|
||||||
@@ -647,7 +647,7 @@ class Boss:
|
|||||||
break
|
break
|
||||||
|
|
||||||
def kitty_shell(self, window_type):
|
def kitty_shell(self, window_type):
|
||||||
cmd = ['kitty', '@']
|
cmd = [kitty_exe(), '@']
|
||||||
if window_type == 'tab':
|
if window_type == 'tab':
|
||||||
window = self._new_tab(cmd).active_window
|
window = self._new_tab(cmd).active_window
|
||||||
elif window_type == 'os_window':
|
elif window_type == 'os_window':
|
||||||
|
|||||||
@@ -21,6 +21,22 @@ ScreenGeometry = namedtuple('ScreenGeometry', 'xstart ystart xnum ynum dx dy')
|
|||||||
WindowGeometry = namedtuple('WindowGeometry', 'left top right bottom xnum ynum')
|
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():
|
def _get_config_dir():
|
||||||
if 'KITTY_CONFIG_DIRECTORY' in os.environ:
|
if 'KITTY_CONFIG_DIRECTORY' in os.environ:
|
||||||
return os.path.abspath(os.path.expanduser(os.environ['KITTY_CONFIG_DIRECTORY']))
|
return os.path.abspath(os.path.expanduser(os.environ['KITTY_CONFIG_DIRECTORY']))
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ from .boss import Boss
|
|||||||
from .cli import create_opts, parse_args
|
from .cli import create_opts, parse_args
|
||||||
from .config import cached_values_for, initial_window_size_func
|
from .config import cached_values_for, initial_window_size_func
|
||||||
from .constants import (
|
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 (
|
from .fast_data_types import (
|
||||||
GLFW_MOD_SUPER, create_os_window, free_font_data, glfw_init,
|
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)
|
print('Failed to set locale with no LANG, ignoring', file=sys.stderr)
|
||||||
|
|
||||||
# Ensure kitty is in PATH
|
# 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))
|
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:
|
if rpath and rpath not in items:
|
||||||
os.environ['PATH'] += os.pathsep + rpath
|
os.environ['PATH'] += os.pathsep + rpath
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from .config_data import to_layout_names
|
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 .layout import all_layouts
|
||||||
from .utils import log_error
|
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:
|
if special_window is None:
|
||||||
cmd = args.args if args and args.args else resolved_shell(opts)
|
cmd = args.args if args and args.args else resolved_shell(opts)
|
||||||
if args.hold:
|
if args.hold:
|
||||||
cmd = ['kitty', '+hold'] + cmd
|
cmd = [kitty_exe(), '+hold'] + cmd
|
||||||
from kitty.tabs import SpecialWindow
|
from kitty.tabs import SpecialWindow
|
||||||
k = {'cwd_from': cwd_from}
|
k = {'cwd_from': cwd_from}
|
||||||
if respect_cwd:
|
if respect_cwd:
|
||||||
|
|||||||
Reference in New Issue
Block a user