Ensure a kitty executable is on PATH even when running from source

This commit is contained in:
Kovid Goyal
2018-01-05 14:56:01 +05:30
parent 973352a98d
commit 88e9c21a3b
3 changed files with 43 additions and 19 deletions

View File

@@ -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:
os.environ['PATH'] += os.pathsep + rpath
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.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('~'))