Ensure a kitty executable is on PATH even when running from source
This commit is contained in:
parent
973352a98d
commit
88e9c21a3b
32
__main__.py
32
__main__.py
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
first_arg = '' if len(sys.argv) < 2 else sys.argv[1]
|
|
||||||
|
|
||||||
|
|
||||||
def icat(args):
|
def icat(args):
|
||||||
from kitty.icat import main
|
from kitty.icat import main
|
||||||
@ -17,16 +15,22 @@ def list_fonts(args):
|
|||||||
main(args)
|
main(args)
|
||||||
|
|
||||||
|
|
||||||
if first_arg in ('icat', '+icat'):
|
def main():
|
||||||
icat(sys.argv[1:])
|
first_arg = '' if len(sys.argv) < 2 else sys.argv[1]
|
||||||
elif first_arg in ('list-fonts', '+list-fonts'):
|
if first_arg in ('icat', '+icat'):
|
||||||
list_fonts(sys.argv[1:])
|
icat(sys.argv[1:])
|
||||||
elif first_arg == '+' and len(sys.argv) > 2:
|
elif first_arg in ('list-fonts', '+list-fonts'):
|
||||||
q = sys.argv[2]
|
list_fonts(sys.argv[1:])
|
||||||
if q == 'icat':
|
elif first_arg == '+' and len(sys.argv) > 2:
|
||||||
icat(sys.argv[2:])
|
q = sys.argv[2]
|
||||||
elif q == 'list-fonts':
|
if q == 'icat':
|
||||||
list_fonts(sys.argv[2:])
|
icat(sys.argv[2:])
|
||||||
else:
|
elif q == 'list-fonts':
|
||||||
from kitty.main import main
|
list_fonts(sys.argv[2:])
|
||||||
|
else:
|
||||||
|
from kitty.main import main
|
||||||
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -109,12 +109,19 @@ def main():
|
|||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
except Exception:
|
except Exception:
|
||||||
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
|
||||||
rpath = getattr(sys, 'bundle_exe_dir', None)
|
rpath = getattr(sys, 'bundle_exe_dir', None)
|
||||||
if rpath:
|
items = frozenset(os.environ['PATH'].split(os.pathsep))
|
||||||
# Ensure kitty bin directory is in PATH
|
if not rpath:
|
||||||
items = frozenset(os.environ['PATH'].split(os.pathsep))
|
for candidate in items:
|
||||||
if rpath not in items:
|
if os.access(os.path.join(candidate, 'kitty'), os.X_OK):
|
||||||
os.environ['PATH'] += os.pathsep + rpath
|
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',
|
if os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES',
|
||||||
None) == '1' and getattr(sys, 'frozen', True):
|
None) == '1' and getattr(sys, 'frozen', True):
|
||||||
os.chdir(os.path.expanduser('~'))
|
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