Ensure a kitty executable is on PATH even when running from source
This commit is contained in:
parent
973352a98d
commit
88e9c21a3b
@ -4,8 +4,6 @@
|
||||
|
||||
import sys
|
||||
|
||||
first_arg = '' if len(sys.argv) < 2 else sys.argv[1]
|
||||
|
||||
|
||||
def icat(args):
|
||||
from kitty.icat import main
|
||||
@ -17,6 +15,8 @@ def list_fonts(args):
|
||||
main(args)
|
||||
|
||||
|
||||
def main():
|
||||
first_arg = '' if len(sys.argv) < 2 else sys.argv[1]
|
||||
if first_arg in ('icat', '+icat'):
|
||||
icat(sys.argv[1:])
|
||||
elif first_arg in ('list-fonts', '+list-fonts'):
|
||||
@ -30,3 +30,7 @@ elif first_arg == '+' and len(sys.argv) > 2:
|
||||
else:
|
||||
from kitty.main import main
|
||||
main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@ -109,12 +109,19 @@ def main():
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
except Exception:
|
||||
print('Failed to set locale with no LANG, ignoring', file=sys.stderr)
|
||||
|
||||
# Ensure kitty is in PATH
|
||||
rpath = getattr(sys, 'bundle_exe_dir', None)
|
||||
if rpath:
|
||||
# Ensure kitty bin directory is in PATH
|
||||
items = frozenset(os.environ['PATH'].split(os.pathsep))
|
||||
if rpath not in items:
|
||||
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.dirname(os.path.abspath(__file__))), 'launcher')
|
||||
if rpath and rpath not in items:
|
||||
os.environ['PATH'] += os.pathsep + rpath
|
||||
|
||||
if os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES',
|
||||
None) == '1' and getattr(sys, 'frozen', True):
|
||||
os.chdir(os.path.expanduser('~'))
|
||||
|
||||
13
launcher/kitty
Executable file
13
launcher/kitty
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, base)
|
||||
with open(os.path.join(base, '__main__.py')) as f:
|
||||
src = f.read()
|
||||
code = compile(src, f.name, 'exec')
|
||||
exec(code, {'__name__': '__main__'})
|
||||
Loading…
x
Reference in New Issue
Block a user