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

View File

@ -102,9 +102,8 @@
use str
if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-) {
# SSH wrapper that preserves Ghostty features across remote connections
fn ssh {|@args|
var ssh-term = ""
var ssh-term = "xterm-256color"
var ssh-opts = []
# Configure environment variables for remote session
@ -115,28 +114,26 @@
# Install terminfo on remote host if needed
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-hostname = ""
for line (str:split "\n" $ssh-config) {
var parts = (str:split " " $line)
if (> (count $parts) 1) {
if (eq $parts[0] user) {
set ssh-user = $parts[1]
} elif (eq $parts[0] hostname) {
set ssh-hostname = $parts[1]
}
if (and (not-eq $ssh-user "") (not-eq $ssh-hostname "")) {
break
try {
var ssh-config = (external ssh -G $@args 2>/dev/null | slurp)
for line (str:split "\n" $ssh-config) {
var parts = (str:split " " $line)
if (> (count $parts) 1) {
if (eq $parts[0] user) {
set ssh-user = $parts[1]
} elif (eq $parts[0] hostname) {
set ssh-hostname = $parts[1]
}
if (and (not-eq $ssh-user "") (not-eq $ssh-hostname "")) {
break
}
}
}
} catch {
# ssh config failed
}
var ssh-target = $ssh-user"@"$ssh-hostname
@ -157,103 +154,75 @@
try {
external infocmp --help >/dev/null 2>&1
try {
external base64 --help >/dev/null 2>&1
var ssh-terminfo = ""
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 {
var base64-help = (external base64 --help 2>&1 | 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)
}
set ssh-cpath-dir = (external mktemp -d "/tmp/ghostty-ssh-"$ssh-user".XXXXXX" 2>/dev/null | slurp)
} 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 "") {
echo "Setting up Ghostty terminfo on "$ssh-hostname"..." >&2
var ssh-cpath-dir = ""
try {
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"
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]
var terminfo-install-success = $false
try {
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 '
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 $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
}
# 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 {
echo "Warning: Could not generate terminfo data." >&2
set ssh-term = "xterm-256color"
echo "Warning: Failed to install terminfo." >&2
}
} catch {
echo "Warning: base64 command not available for terminfo installation." >&2
set ssh-term = "xterm-256color"
} else {
echo "Warning: Could not generate terminfo data." >&2
}
} catch {
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
if (and (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-env) (eq $ssh-term "")) {
set ssh-term = "xterm-256color"
}
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 {
# Execute SSH with TERM environment variable
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
}
}

View File

@ -89,7 +89,7 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
# SSH Integration
if string match -q '*ssh-*' -- "$GHOSTTY_SHELL_FEATURES"
function ssh --wraps=ssh --description "SSH wrapper with Ghostty integration"
set -l ssh_term ""
set -l ssh_term "xterm-256color"
set -l ssh_opts
# 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
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_hostname
for line in $ssh_config
for line in (command ssh -G $argv 2>/dev/null)
set -l parts (string split ' ' -- $line)
if test (count $parts) -ge 2
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"
set ssh_term "xterm-ghostty"
else if command -v infocmp >/dev/null 2>&1
if not command -v base64 >/dev/null 2>&1
echo "Warning: base64 command not available for terminfo installation." >&2
set ssh_term "xterm-256color"
else
set -l ssh_terminfo
set -l ssh_base64_decode_cmd
set -l ssh_terminfo
set -l ssh_cpath_dir
set -l ssh_cpath
# BSD vs GNU base64 compatibility
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
set ssh_terminfo (infocmp -0 -x xterm-ghostty 2>/dev/null)
if test -n "$ssh_terminfo"
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 test -n "$ssh_terminfo"
echo "Setting up Ghostty terminfo on $ssh_hostname..." >&2
if echo "$ssh_terminfo" | eval $ssh_base64_decode_cmd | command ssh $ssh_opts -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s $argv '
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
' 2>/dev/null
echo "Terminfo setup complete on $ssh_hostname." >&2
set ssh_term "xterm-ghostty"
set -a ssh_opts -o "ControlPath=$ssh_cpath"
set ssh_cpath_dir (mktemp -d "/tmp/ghostty-ssh-$ssh_user.XXXXXX" 2>/dev/null; or echo "/tmp/ghostty-ssh-$ssh_user."(random))
set ssh_cpath "$ssh_cpath_dir/socket"
# 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
else
echo "Warning: Failed to install terminfo." >&2
set ssh_term "xterm-256color"
if echo "$ssh_terminfo" | command ssh $ssh_opts -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s $argv '
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
' 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 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
else
echo "Warning: Could not generate terminfo data." >&2
set ssh_term "xterm-256color"
echo "Warning: Failed to install terminfo." >&2
end
else
echo "Warning: Could not generate terminfo data." >&2
end
else
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
# Execute SSH with environment handling
if string match -q '*ssh-env*' -- "$GHOSTTY_SHELL_FEATURES"; and test -z "$ssh_term"
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
# Execute SSH with TERM environment variable
env TERM="$ssh_term" command ssh $ssh_opts $argv
end
end

View File

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