Implement an option to control the installation of the kitty bootstrap script

This commit is contained in:
Kovid Goyal
2022-04-03 20:30:16 +05:30
parent a2d1140229
commit c07f164154
7 changed files with 66 additions and 3 deletions

View File

@@ -169,6 +169,24 @@ fi' > "$sh_script"
exec "$login_shell"
}
install_kitty_bootstrap() {
case "$(command uname)" in
Linux) ;;
Darwin) ;;
*) return ;;
esac
kitty_exists="n"
command -v kitty 2> /dev/null > /dev/null && kitty_exists="y"
if [ "$kitty_remote" = "yes" -o "$kitty_remote-$kitty_exists" = "if-needed-n" ]; then
kitty_dir="$data_dir/kitty/bin"
if [ "$kitty_exists" = "y" ]; then
export PATH="$kitty_dir:$PATH"
else
export PATH="$PATH:$kitty_dir"
fi
fi
}
prepare_for_exec() {
if [ -n "$leading_data" ]; then
# clear current line as it might have things echoed on it from leading_data
@@ -177,6 +195,7 @@ prepare_for_exec() {
printf "\r\033[K" > /dev/tty
fi
[ -f "$HOME/.terminfo/kitty.terminfo" ] || die "Incomplete extraction of ssh data"
install_kitty_bootstrap
[ -n "$login_shell" ] || using_getent || using_id || using_python || using_perl || using_passwd || using_shell_env || login_shell="sh"
shell_name=$(command basename $login_shell)

View File

@@ -258,6 +258,19 @@ def exec_with_shell_integration():
exec_bash_with_integration()
def install_kitty_bootstrap():
kitty_remote = os.environ.pop('KITTY_REMOTE', '')
if os.uname().sysname not in ('Linux', 'Darwin'):
return
kitty_exists = shutil.which('kitty')
if kitty_remote == 'yes' or (kitty_remote == 'if-needed' and not kitty_exists):
kitty_dir = os.path.join(data_dir, 'kitty', 'bin')
if kitty_exists:
os.environ['PATH'] = kitty_dir + os.pathsep + os.environ['PATH']
else:
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + kitty_dir
def main():
global tty_file_obj, login_shell
# the value of O_CLOEXEC below is on macOS which is most likely to not have
@@ -271,6 +284,7 @@ def main():
finally:
cleanup()
cwd = os.environ.pop('KITTY_LOGIN_CWD', '')
install_kitty_bootstrap()
if cwd:
os.chdir(cwd)
ksi = frozenset(filter(None, os.environ.get('KITTY_SHELL_INTEGRATION', '').split()))

View File

@@ -106,6 +106,8 @@ untar_and_read_env() {
unset KITTY_LOGIN_SHELL
login_cwd="$KITTY_LOGIN_CWD"
unset KITTY_LOGIN_CWD
kitty_remote="$KITTY_REMOTE"
unset KITTY_REMOTE
compile_terminfo "$tdir/home"
mv_files_and_dirs "$tdir/home" "$HOME"
[ -e "$tdir/root" ] && mv_files_and_dirs "$tdir/root" ""