refactor: simplify terminfo handling and remove base64 dependency

- Default ssh_term to xterm-256color to eliminate fallback assignments
- Remove base64 and replace infocmp -Q2 with standard -0 -x options for
compatibility
- Use process substitution instead of intermediate ssh_config variable
- Always set TERM explicitly since ssh_term is always defined
This commit is contained in:
Jason Rayne
2025-07-07 11:33:26 -07:00
parent 22edfd2c5d
commit f279937377
4 changed files with 145 additions and 258 deletions

View File

@ -99,7 +99,7 @@ fi
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
ssh() { ssh() {
builtin local ssh_term ssh_opts builtin local ssh_term ssh_opts
ssh_term="" ssh_term="xterm-256color"
ssh_opts=() ssh_opts=()
# Configure environment variables for remote session # Configure environment variables for remote session
@ -110,8 +110,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
# Install terminfo on remote host if needed # Install terminfo on remote host if needed
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then
builtin local ssh_config ssh_user ssh_hostname builtin local ssh_user ssh_hostname
ssh_config=$(builtin command ssh -G "$@" 2>/dev/null)
while IFS=' ' read -r ssh_key ssh_value; do while IFS=' ' read -r ssh_key ssh_value; do
case "$ssh_key" in case "$ssh_key" in
@ -119,7 +118,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
hostname) ssh_hostname="$ssh_value" ;; hostname) ssh_hostname="$ssh_value" ;;
esac esac
[[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break [[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break
done <<< "$ssh_config" done < <(builtin command ssh -G "$@" 2>/dev/null)
builtin local ssh_target="${ssh_user}@${ssh_hostname}" builtin local ssh_target="${ssh_user}@${ssh_hostname}"
@ -133,72 +132,44 @@ if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
if [[ "$ssh_cache_check_success" == "true" ]]; then if [[ "$ssh_cache_check_success" == "true" ]]; then
ssh_term="xterm-ghostty" ssh_term="xterm-ghostty"
elif builtin command -v infocmp >/dev/null 2>&1; then elif builtin command -v infocmp >/dev/null 2>&1; then
if ! builtin command -v base64 >/dev/null 2>&1; then builtin local ssh_terminfo ssh_cpath_dir ssh_cpath
builtin echo "Warning: base64 command not available for terminfo installation." >&2
ssh_term="xterm-256color"
else
builtin local ssh_terminfo ssh_base64_decode_cmd
# BSD vs GNU base64 compatibility ssh_terminfo=$(infocmp -0 -x xterm-ghostty 2>/dev/null)
if base64 --help 2>&1 | grep -q GNU; then
ssh_base64_decode_cmd="base64 -d"
ssh_terminfo=$(infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | base64 -w0 2>/dev/null)
else
ssh_base64_decode_cmd="base64 -D"
ssh_terminfo=$(infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | base64 2>/dev/null | tr -d '\n')
fi
if [[ -n "$ssh_terminfo" ]]; then if [[ -n "$ssh_terminfo" ]]; then
builtin echo "Setting up Ghostty terminfo on $ssh_hostname..." >&2 builtin echo "Setting up Ghostty terminfo on $ssh_hostname..." >&2
builtin local ssh_cpath_dir ssh_cpath
ssh_cpath_dir=$(mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null) || ssh_cpath_dir="/tmp/ghostty-ssh-$ssh_user.$$" ssh_cpath_dir=$(mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null) || ssh_cpath_dir="/tmp/ghostty-ssh-$ssh_user.$$"
ssh_cpath="$ssh_cpath_dir/socket" ssh_cpath="$ssh_cpath_dir/socket"
if builtin echo "$ssh_terminfo" | $ssh_base64_decode_cmd | builtin command ssh "${ssh_opts[@]}" -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s "$@" ' if builtin echo "$ssh_terminfo" | builtin command ssh "${ssh_opts[@]}" -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s "$@" '
infocmp xterm-ghostty >/dev/null 2>&1 && exit 0 infocmp xterm-ghostty >/dev/null 2>&1 && exit 0
command -v tic >/dev/null 2>&1 || exit 1 command -v tic >/dev/null 2>&1 || exit 1
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0 mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0
exit 1 exit 1
' 2>/dev/null; then ' 2>/dev/null; then
builtin echo "Terminfo setup complete on $ssh_hostname." >&2 builtin echo "Terminfo setup complete on $ssh_hostname." >&2
ssh_term="xterm-ghostty" ssh_term="xterm-ghostty"
ssh_opts+=(-o "ControlPath=$ssh_cpath") ssh_opts+=(-o "ControlPath=$ssh_cpath")
# Cache successful installation # Cache successful installation
if [[ -n "$ssh_target" ]] && builtin command -v ghostty >/dev/null 2>&1; then if [[ -n "$ssh_target" ]] && builtin command -v ghostty >/dev/null 2>&1; then
ghostty +ssh-cache --add="$ssh_target" >/dev/null 2>&1 || true ghostty +ssh-cache --add="$ssh_target" >/dev/null 2>&1 || true
fi
else
builtin echo "Warning: Failed to install terminfo." >&2
ssh_term="xterm-256color"
fi fi
else else
builtin echo "Warning: Could not generate terminfo data." >&2 builtin echo "Warning: Failed to install terminfo." >&2
ssh_term="xterm-256color"
fi fi
else
builtin echo "Warning: Could not generate terminfo data." >&2
fi fi
else else
builtin echo "Warning: ghostty command not available for cache management." >&2 builtin echo "Warning: ghostty command not available for cache management." >&2
ssh_term="xterm-256color"
fi
else
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]]; then
ssh_term="xterm-256color"
fi fi
fi fi
fi fi
# Execute SSH with environment handling # Execute SSH with TERM environment variable
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* && -z "$ssh_term" ]]; then TERM="$ssh_term" builtin command ssh "${ssh_opts[@]}" "$@"
ssh_term="xterm-256color"
fi
if [[ -n "$ssh_term" ]]; then
TERM="$ssh_term" builtin command ssh "${ssh_opts[@]}" "$@"
else
builtin command ssh "${ssh_opts[@]}" "$@"
fi
} }
fi fi

View File

@ -102,9 +102,8 @@
use str use str
if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-) { if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-) {
# SSH wrapper that preserves Ghostty features across remote connections
fn ssh {|@args| fn ssh {|@args|
var ssh-term = "" var ssh-term = "xterm-256color"
var ssh-opts = [] var ssh-opts = []
# Configure environment variables for remote session # Configure environment variables for remote session
@ -115,28 +114,26 @@
# Install terminfo on remote host if needed # Install terminfo on remote host if needed
if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-terminfo) { if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-terminfo) {
var ssh-config = ""
try {
set ssh-config = (external ssh -G $@args 2>/dev/null | slurp)
} catch {
set ssh-config = ""
}
var ssh-user = "" var ssh-user = ""
var ssh-hostname = "" var ssh-hostname = ""
for line (str:split "\n" $ssh-config) { try {
var parts = (str:split " " $line) var ssh-config = (external ssh -G $@args 2>/dev/null | slurp)
if (> (count $parts) 1) { for line (str:split "\n" $ssh-config) {
if (eq $parts[0] user) { var parts = (str:split " " $line)
set ssh-user = $parts[1] if (> (count $parts) 1) {
} elif (eq $parts[0] hostname) { if (eq $parts[0] user) {
set ssh-hostname = $parts[1] set ssh-user = $parts[1]
} } elif (eq $parts[0] hostname) {
if (and (not-eq $ssh-user "") (not-eq $ssh-hostname "")) { set ssh-hostname = $parts[1]
break }
if (and (not-eq $ssh-user "") (not-eq $ssh-hostname "")) {
break
}
} }
} }
} catch {
# ssh config failed
} }
var ssh-target = $ssh-user"@"$ssh-hostname var ssh-target = $ssh-user"@"$ssh-hostname
@ -157,103 +154,75 @@
try { try {
external infocmp --help >/dev/null 2>&1 external infocmp --help >/dev/null 2>&1
try { var ssh-terminfo = ""
external base64 --help >/dev/null 2>&1 var ssh-cpath-dir = ""
var ssh-cpath = ""
try {
set ssh-terminfo = (external infocmp -0 -x xterm-ghostty 2>/dev/null | slurp)
} catch {
set ssh-terminfo = ""
}
if (not-eq $ssh-terminfo "") {
echo "Setting up Ghostty terminfo on "$ssh-hostname"..." >&2
# Generate terminfo data (BSD base64 compatibility)
var ssh-terminfo = ""
var ssh-base64-decode-cmd = ""
try { try {
var base64-help = (external base64 --help 2>&1 | slurp) set ssh-cpath-dir = (external mktemp -d "/tmp/ghostty-ssh-"$ssh-user".XXXXXX" 2>/dev/null | slurp)
if (str:contains $base64-help GNU) {
set ssh-base64-decode-cmd = "base64 -d"
set ssh-terminfo = (external infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | external base64 -w0 2>/dev/null | slurp)
} else {
set ssh-base64-decode-cmd = "base64 -D"
set ssh-terminfo = (external infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | external base64 2>/dev/null | external tr -d '\n' | slurp)
}
} catch { } catch {
set ssh-terminfo = "" set ssh-cpath-dir = "/tmp/ghostty-ssh-"$ssh-user"."(randint 10000 99999)
}
set ssh-cpath = $ssh-cpath-dir"/socket"
var terminfo-install-success = $false
try {
echo $ssh-terminfo | external ssh $@ssh-opts -o ControlMaster=yes -o ControlPath=$ssh-cpath -o ControlPersist=60s $@args '
infocmp xterm-ghostty >/dev/null 2>&1 && exit 0
command -v tic >/dev/null 2>&1 || exit 1
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0
exit 1
' >/dev/null 2>&1
set terminfo-install-success = $true
} catch {
set terminfo-install-success = $false
} }
if (not-eq $ssh-terminfo "") { if $terminfo-install-success {
echo "Setting up Ghostty terminfo on "$ssh-hostname"..." >&2 echo "Terminfo setup complete on "$ssh-hostname"." >&2
var ssh-cpath-dir = "" set ssh-term = "xterm-ghostty"
try { set ssh-opts = [$@ssh-opts -o ControlPath=$ssh-cpath]
set ssh-cpath-dir = (external mktemp -d "/tmp/ghostty-ssh-"$ssh-user".XXXXXX" 2>/dev/null | slurp)
} catch {
set ssh-cpath-dir = "/tmp/ghostty-ssh-"$ssh-user"."(randint 10000 99999)
}
var ssh-cpath = $ssh-cpath-dir"/socket"
var terminfo-install-success = $false # Cache successful installation
try { if (and (not-eq $ssh-target "") (has-external ghostty)) {
echo $ssh-terminfo | external sh -c $ssh-base64-decode-cmd | external ssh $@ssh-opts -o ControlMaster=yes -o ControlPath=$ssh-cpath -o ControlPersist=60s $@args ' try {
infocmp xterm-ghostty >/dev/null 2>&1 && exit 0 external ghostty +ssh-cache --add=$ssh-target >/dev/null 2>&1
command -v tic >/dev/null 2>&1 || exit 1 } catch {
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0 # cache add failed
exit 1
' >/dev/null 2>&1
set terminfo-install-success = $true
} catch {
set terminfo-install-success = $false
}
if $terminfo-install-success {
echo "Terminfo setup complete on "$ssh-hostname"." >&2
set ssh-term = "xterm-ghostty"
set ssh-opts = [$@ssh-opts -o ControlPath=$ssh-cpath]
# Cache successful installation
if (and (not-eq $ssh-target "") (has-external ghostty)) {
try {
external ghostty +ssh-cache --add=$ssh-target >/dev/null 2>&1
} catch {
# cache add failed
}
} }
} else {
echo "Warning: Failed to install terminfo." >&2
set ssh-term = "xterm-256color"
} }
} else { } else {
echo "Warning: Could not generate terminfo data." >&2 echo "Warning: Failed to install terminfo." >&2
set ssh-term = "xterm-256color"
} }
} catch { } else {
echo "Warning: base64 command not available for terminfo installation." >&2 echo "Warning: Could not generate terminfo data." >&2
set ssh-term = "xterm-256color"
} }
} catch { } catch {
echo "Warning: ghostty command not available for cache management." >&2 echo "Warning: ghostty command not available for cache management." >&2
set ssh-term = "xterm-256color"
} }
} }
} else {
if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-env) {
set ssh-term = "xterm-256color"
}
} }
} }
# Execute SSH with environment handling # Execute SSH with TERM environment variable
if (and (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-env) (eq $ssh-term "")) { var old-term = $E:TERM
set ssh-term = "xterm-256color" set-env TERM $ssh-term
} try {
if (not-eq $ssh-term "") {
var old-term = $E:TERM
set-env TERM $ssh-term
try {
external ssh $@ssh-opts $@args
} catch e {
set-env TERM $old-term
fail $e
}
set-env TERM $old-term
} else {
external ssh $@ssh-opts $@args external ssh $@ssh-opts $@args
} catch e {
set-env TERM $old-term
fail $e
} }
set-env TERM $old-term
} }
} }

View File

@ -89,7 +89,7 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
# SSH Integration # SSH Integration
if string match -q '*ssh-*' -- "$GHOSTTY_SHELL_FEATURES" if string match -q '*ssh-*' -- "$GHOSTTY_SHELL_FEATURES"
function ssh --wraps=ssh --description "SSH wrapper with Ghostty integration" function ssh --wraps=ssh --description "SSH wrapper with Ghostty integration"
set -l ssh_term "" set -l ssh_term "xterm-256color"
set -l ssh_opts set -l ssh_opts
# Configure environment variables for remote session # Configure environment variables for remote session
@ -100,11 +100,10 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
# Install terminfo on remote host if needed # Install terminfo on remote host if needed
if string match -q '*ssh-terminfo*' -- "$GHOSTTY_SHELL_FEATURES" if string match -q '*ssh-terminfo*' -- "$GHOSTTY_SHELL_FEATURES"
set -l ssh_config (command ssh -G $argv 2>/dev/null)
set -l ssh_user set -l ssh_user
set -l ssh_hostname set -l ssh_hostname
for line in $ssh_config for line in (command ssh -G $argv 2>/dev/null)
set -l parts (string split ' ' -- $line) set -l parts (string split ' ' -- $line)
if test (count $parts) -ge 2 if test (count $parts) -ge 2
switch $parts[1] switch $parts[1]
@ -133,71 +132,46 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
if test "$ssh_cache_check_success" = "true" if test "$ssh_cache_check_success" = "true"
set ssh_term "xterm-ghostty" set ssh_term "xterm-ghostty"
else if command -v infocmp >/dev/null 2>&1 else if command -v infocmp >/dev/null 2>&1
if not command -v base64 >/dev/null 2>&1 set -l ssh_terminfo
echo "Warning: base64 command not available for terminfo installation." >&2 set -l ssh_cpath_dir
set ssh_term "xterm-256color" set -l ssh_cpath
else
set -l ssh_terminfo
set -l ssh_base64_decode_cmd
# BSD vs GNU base64 compatibility set ssh_terminfo (infocmp -0 -x xterm-ghostty 2>/dev/null)
if base64 --help 2>&1 | grep -q GNU
set ssh_base64_decode_cmd "base64 -d"
set ssh_terminfo (infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | base64 -w0 2>/dev/null)
else
set ssh_base64_decode_cmd "base64 -D"
set ssh_terminfo (infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | base64 2>/dev/null | tr -d '\n')
end
if test -n "$ssh_terminfo" if test -n "$ssh_terminfo"
echo "Setting up Ghostty terminfo on $ssh_hostname..." >&2 echo "Setting up Ghostty terminfo on $ssh_hostname..." >&2
set -l ssh_cpath_dir (mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null; or echo "/tmp/ghostty-ssh-$ssh_user."(random))
set -l ssh_cpath "$ssh_cpath_dir/socket"
if echo "$ssh_terminfo" | eval $ssh_base64_decode_cmd | command ssh $ssh_opts -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s $argv ' set ssh_cpath_dir (mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null; or echo "/tmp/ghostty-ssh-$ssh_user."(random))
infocmp xterm-ghostty >/dev/null 2>&1 && exit 0 set ssh_cpath "$ssh_cpath_dir/socket"
command -v tic >/dev/null 2>&1 || exit 1
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0
exit 1
' 2>/dev/null
echo "Terminfo setup complete on $ssh_hostname." >&2
set ssh_term "xterm-ghostty"
set -a ssh_opts -o "ControlPath=$ssh_cpath"
# Cache successful installation if echo "$ssh_terminfo" | command ssh $ssh_opts -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s $argv '
if test -n "$ssh_target"; and command -v ghostty >/dev/null 2>&1 infocmp xterm-ghostty >/dev/null 2>&1 && exit 0
ghostty +ssh-cache --add="$ssh_target" >/dev/null 2>&1; or true command -v tic >/dev/null 2>&1 || exit 1
end mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0
else exit 1
echo "Warning: Failed to install terminfo." >&2 ' 2>/dev/null
set ssh_term "xterm-256color" echo "Terminfo setup complete on $ssh_hostname." >&2
set ssh_term "xterm-ghostty"
set -a ssh_opts -o "ControlPath=$ssh_cpath"
# Cache successful installation
if test -n "$ssh_target"; and command -v ghostty >/dev/null 2>&1
ghostty +ssh-cache --add="$ssh_target" >/dev/null 2>&1; or true
end end
else else
echo "Warning: Could not generate terminfo data." >&2 echo "Warning: Failed to install terminfo." >&2
set ssh_term "xterm-256color"
end end
else
echo "Warning: Could not generate terminfo data." >&2
end end
else else
echo "Warning: ghostty command not available for cache management." >&2 echo "Warning: ghostty command not available for cache management." >&2
set ssh_term "xterm-256color"
end
else
if string match -q '*ssh-env*' -- "$GHOSTTY_SHELL_FEATURES"
set ssh_term "xterm-256color"
end end
end end
end end
# Execute SSH with environment handling # Execute SSH with TERM environment variable
if string match -q '*ssh-env*' -- "$GHOSTTY_SHELL_FEATURES"; and test -z "$ssh_term" env TERM="$ssh_term" command ssh $ssh_opts $argv
set ssh_term "xterm-256color"
end
if test -n "$ssh_term"
env TERM="$ssh_term" command ssh $ssh_opts $argv
else
command ssh $ssh_opts $argv
end
end end
end end

View File

@ -251,7 +251,7 @@ _ghostty_deferred_init() {
setopt local_options no_glob_subst setopt local_options no_glob_subst
local ssh_term ssh_opts local ssh_term ssh_opts
ssh_term="" ssh_term="xterm-256color"
ssh_opts=() ssh_opts=()
# Configure environment variables for remote session # Configure environment variables for remote session
@ -262,8 +262,7 @@ _ghostty_deferred_init() {
# Install terminfo on remote host if needed # Install terminfo on remote host if needed
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-terminfo* ]]; then
local ssh_config ssh_user ssh_hostname local ssh_user ssh_hostname
ssh_config=$(command ssh -G "$@" 2>/dev/null)
while IFS=' ' read -r ssh_key ssh_value; do while IFS=' ' read -r ssh_key ssh_value; do
case "$ssh_key" in case "$ssh_key" in
@ -271,7 +270,7 @@ _ghostty_deferred_init() {
hostname) ssh_hostname="$ssh_value" ;; hostname) ssh_hostname="$ssh_value" ;;
esac esac
[[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break [[ -n "$ssh_user" && -n "$ssh_hostname" ]] && break
done <<< "$ssh_config" done < <(command ssh -G "$@" 2>/dev/null)
local ssh_target="${ssh_user}@${ssh_hostname}" local ssh_target="${ssh_user}@${ssh_hostname}"
@ -285,70 +284,44 @@ _ghostty_deferred_init() {
if [[ "$ssh_cache_check_success" == "true" ]]; then if [[ "$ssh_cache_check_success" == "true" ]]; then
ssh_term="xterm-ghostty" ssh_term="xterm-ghostty"
elif (( $+commands[infocmp] )); then elif (( $+commands[infocmp] )); then
if ! (( $+commands[base64] )); then local ssh_terminfo ssh_cpath_dir ssh_cpath
print "Warning: base64 command not available for terminfo installation." >&2
ssh_term="xterm-256color"
else
local ssh_terminfo ssh_base64_decode_cmd
# BSD vs GNU base64 compatibility ssh_terminfo=$(infocmp -0 -x xterm-ghostty 2>/dev/null)
if base64 --help 2>&1 | grep -q GNU; then
ssh_base64_decode_cmd="base64 -d"
ssh_terminfo=$(infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | base64 -w0 2>/dev/null)
else
ssh_base64_decode_cmd="base64 -D"
ssh_terminfo=$(infocmp -0 -Q2 -q xterm-ghostty 2>/dev/null | base64 2>/dev/null | tr -d '\n')
fi
if [[ -n "$ssh_terminfo" ]]; then if [[ -n "$ssh_terminfo" ]]; then
print "Setting up Ghostty terminfo on $ssh_hostname..." >&2 print "Setting up Ghostty terminfo on $ssh_hostname..." >&2
local ssh_cpath_dir ssh_cpath
ssh_cpath_dir=$(mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null) || ssh_cpath_dir="/tmp/ghostty-ssh-$ssh_user.$$" ssh_cpath_dir=$(mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null) || ssh_cpath_dir="/tmp/ghostty-ssh-$ssh_user.$$"
ssh_cpath="$ssh_cpath_dir/socket" ssh_cpath="$ssh_cpath_dir/socket"
if print "$ssh_terminfo" | $ssh_base64_decode_cmd | command ssh "${ssh_opts[@]}" -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s "$@" ' if print "$ssh_terminfo" | command ssh "${ssh_opts[@]}" -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s "$@" '
infocmp xterm-ghostty >/dev/null 2>&1 && exit 0 infocmp xterm-ghostty >/dev/null 2>&1 && exit 0
command -v tic >/dev/null 2>&1 || exit 1 command -v tic >/dev/null 2>&1 || exit 1
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0 mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && exit 0
exit 1 exit 1
' 2>/dev/null; then ' 2>/dev/null; then
print "Terminfo setup complete on $ssh_hostname." >&2 print "Terminfo setup complete on $ssh_hostname." >&2
ssh_term="xterm-ghostty" ssh_term="xterm-ghostty"
ssh_opts+=(-o "ControlPath=$ssh_cpath") ssh_opts+=(-o "ControlPath=$ssh_cpath")
# Cache successful installation # Cache successful installation
if [[ -n "$ssh_target" ]] && (( $+commands[ghostty] )); then if [[ -n "$ssh_target" ]] && (( $+commands[ghostty] )); then
ghostty +ssh-cache --add="$ssh_target" >/dev/null 2>&1 || true ghostty +ssh-cache --add="$ssh_target" >/dev/null 2>&1 || true
fi
else
print "Warning: Failed to install terminfo." >&2
ssh_term="xterm-256color"
fi fi
else else
print "Warning: Could not generate terminfo data." >&2 print "Warning: Failed to install terminfo." >&2
ssh_term="xterm-256color"
fi fi
else
print "Warning: Could not generate terminfo data." >&2
fi fi
else else
print "Warning: ghostty command not available for cache management." >&2 print "Warning: ghostty command not available for cache management." >&2
ssh_term="xterm-256color"
fi fi
else
[[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* ]] && ssh_term="xterm-256color"
fi fi
fi fi
# Execute SSH with environment handling # Execute SSH with TERM environment variable
if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-env* && -z "$ssh_term" ]]; then TERM="$ssh_term" command ssh "${ssh_opts[@]}" "$@"
ssh_term="xterm-256color"
fi
if [[ -n "$ssh_term" ]]; then
TERM="$ssh_term" command ssh "${ssh_opts[@]}" "$@"
else
command ssh "${ssh_opts[@]}" "$@"
fi
} }
fi fi