mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Drop the requirement for having python on the server when using the ssh kitten
This commit is contained in:
@@ -7,7 +7,6 @@ import sys
|
||||
|
||||
SHELL_SCRIPT = '''\
|
||||
#!/bin/sh
|
||||
|
||||
tmp=$(mktemp /tmp/terminfo.XXXXXX)
|
||||
cat >$tmp << 'TERMEOF'
|
||||
TERMINFO
|
||||
@@ -17,47 +16,16 @@ tic_out=$(tic -x -o ~/.terminfo $tmp 2>&1)
|
||||
rc=$?
|
||||
rm $tmp
|
||||
if [ "$rc" != "0" ]; then echo "$tic_out"; exit 1; fi
|
||||
if [ -z "$USER" ]; then USER=$(whoami); fi
|
||||
search_for_python() {
|
||||
# We have to search for python as Ubuntu, in its infinite wisdom decided
|
||||
# to release 18.04 with no python symlink, making it impossible to run polyglot
|
||||
# python scripts.
|
||||
if [ -z "$USER" ]; then export USER=$(whoami); fi
|
||||
|
||||
# We cannot use command -v as it is not implemented in the posh shell shipped with
|
||||
# Ubuntu/Debian. Similarly, there is no guarantee that which is installed.
|
||||
# Shell scripting is a horrible joke, thank heavens for python.
|
||||
local IFS=:
|
||||
if [ $ZSH_VERSION ]; then
|
||||
# zsh does not split by default
|
||||
setopt sh_word_split
|
||||
fi
|
||||
local candidate_path
|
||||
local candidate_python
|
||||
local pythons=python3:python2
|
||||
# disable pathname expansion (globbing)
|
||||
set -f
|
||||
for candidate_path in $PATH
|
||||
do
|
||||
if [ ! -z $candidate_path ]
|
||||
then
|
||||
for candidate_python in $pythons
|
||||
do
|
||||
if [ ! -z "$candidate_path" ]
|
||||
then
|
||||
if [ -x "$candidate_path/$candidate_python" ]
|
||||
then
|
||||
printf "$candidate_path/$candidate_python"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
set +f
|
||||
printf "python"
|
||||
}
|
||||
PYTHON=$(search_for_python)
|
||||
exec $PYTHON -c "import os, pwd; shell = pwd.getpwuid(os.geteuid()).pw_shell or 'sh'; os.execlp(shell, '-' + os.path.basename(shell))"
|
||||
|
||||
# We need to pass the first argument to the executed program with a leading -
|
||||
# to make sure the shell executes as a login shell. Note that not all shells
|
||||
# support exec -a
|
||||
shell_name=$(basename $0)
|
||||
exec -a "-$shell_name" "$0"
|
||||
# exec does not support -a
|
||||
exec "$0" --login
|
||||
'''
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user