diff --git a/shell-integration/ssh/bootstrap.py b/shell-integration/ssh/bootstrap.py index 2724aba92..0ed457741 100644 --- a/shell-integration/ssh/bootstrap.py +++ b/shell-integration/ssh/bootstrap.py @@ -89,19 +89,22 @@ def move(src, base_dest): os.rename(x.path, dest) -def compile_terminfo(): +def compile_terminfo(base): if not shutil.which('tic'): return tname = '.terminfo' if os.path.exists('/usr/share/misc/terminfo.cdb'): tname += '.cdb' - cp = subprocess.run( - ['tic', '-x', '-o', os.path.join(HOME, tname), os.path.join(HOME, '.terminfo', 'kitty.terminfo')], - stdout=subprocess.PIPE, stderr=subprocess.STDOUT - ) - if cp.returncode != 0: - sys.stderr.buffer.write(cp.stdout) - raise SystemExit('Failed to compile the terminfo database') + os.environ['TERMINFO'] = os.path.join(HOME, tname) + tic = shutil.which('tic') + if tic: + cp = subprocess.run( + [tic, '-x', '-o', os.path.join(base, tname), os.path.join(base, '.terminfo', 'kitty.terminfo')], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) + if cp.returncode != 0: + sys.stderr.buffer.write(cp.stdout) + raise SystemExit('Failed to compile the terminfo database') def get_data(): @@ -138,6 +141,7 @@ def get_data(): apply_env_vars(env_vars) data_dir = os.path.join(HOME, os.environ.pop('KITTY_SSH_KITTEN_DATA_DIR')) shell_integration_dir = os.path.join(data_dir, 'shell-integration') + compile_terminfo(tdir + '/home') move(tdir + '/home', HOME) if os.path.exists(tdir + '/root'): move(tdir + '/root', '/') @@ -213,7 +217,6 @@ def main(): finally: cleanup() ksi = frozenset(filter(None, os.environ.pop('KITTY_SHELL_INTEGRATION', '').split())) - compile_terminfo() exec_cmd = b'EXEC_CMD' if exec_cmd: cmd = base64.standard_b64decode(exec_cmd).decode('utf-8') diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 8e788acb2..9f58f859f 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -110,6 +110,24 @@ mv_files_and_dirs() { cd "$cwd"; } +compile_terminfo() { + # export TERMINFO + tname=".terminfo" + if [ -e "/usr/share/misc/terminfo.cdb" ]; then + # NetBSD requires this see https://github.com/kovidgoyal/kitty/issues/4622 + tname=".terminfo.cdb" + fi + export TERMINFO="$HOME/$tname" + + # compile terminfo for this system + if [ -x "$(command -v tic)" ]; then + tic_out=$(command tic -x -o "$1/$tname" "$1/.terminfo/kitty.terminfo" 2>&1) + rc=$? + if [ "$rc" != "0" ]; then die "$tic_out"; fi + fi +} + + untar_and_read_env() { # extract the tar file atomically, in the sense that any file from the # tarfile is only put into place after it has been fully written to disk @@ -120,6 +138,7 @@ untar_and_read_env() { data_file="$tdir/data.sh"; [ -f "$data_file" ] && . "$data_file"; data_dir="$HOME/$KITTY_SSH_KITTEN_DATA_DIR" + compile_terminfo "$tdir/home" mv_files_and_dirs "$tdir/home" "$HOME" [ -e "$tdir/root" ] && mv_files_and_dirs "$tdir/root" "" command rm -rf "$tdir"; @@ -160,20 +179,6 @@ if [ "$tty_ok" = "y" ]; then shell_integration_dir="$data_dir/shell-integration" [ -f "$HOME/.terminfo/kitty.terminfo" ] || die "Incomplete extraction of ssh data"; - # export TERMINFO - tname=".terminfo" - if [ -e "/usr/share/misc/terminfo.cdb" ]; then - # NetBSD requires this see https://github.com/kovidgoyal/kitty/issues/4622 - tname=".terminfo.cdb" - fi - export TERMINFO="$HOME/$tname" - - # compile terminfo for this system - if [ -x "$(command -v tic)" ]; then - tic_out=$(command tic -x -o "$HOME/$tname" "$HOME/.terminfo/kitty.terminfo" 2>&1) - rc=$? - if [ "$rc" != "0" ]; then die "$tic_out"; fi - fi fi