mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
refactor: apply maintainer feedback to SSH integration scripts across all shells
- Update Bash script (baseline): Simplify cache checking logic, clarify "xterm-ghostty terminfo" message, remove unnecessary ssh_opts from terminfo installation, remove extra success message - Align ZSH/Fish/Elvish with updated Bash: Remove extra success messages, adopt simplified cache checking, standardize setup messages - Apply Elvish improvements: Remove unnecessary try/catch blocks, use idiomatic error handling patterns - Apply Fish improvements: Replace string pattern matching with efficient `contains` checks on split features list
This commit is contained in:
@ -124,12 +124,7 @@ if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
|
||||
|
||||
if [[ -n "$ssh_hostname" ]]; then
|
||||
# Check if terminfo is already cached
|
||||
builtin local ssh_cache_check_success=false
|
||||
if builtin command -v ghostty >/dev/null 2>&1; then
|
||||
ghostty +ssh-cache --host="$ssh_target" >/dev/null 2>&1 && ssh_cache_check_success=true
|
||||
fi
|
||||
|
||||
if [[ "$ssh_cache_check_success" == "true" ]]; then
|
||||
if ghostty +ssh-cache --host="$ssh_target" >/dev/null 2>&1; then
|
||||
ssh_term="xterm-ghostty"
|
||||
elif builtin command -v infocmp >/dev/null 2>&1; then
|
||||
builtin local ssh_terminfo ssh_cpath_dir ssh_cpath
|
||||
@ -137,18 +132,17 @@ if [[ "$GHOSTTY_SHELL_FEATURES" == *ssh-* ]]; then
|
||||
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 echo "Setting up xterm-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"
|
||||
|
||||
if builtin echo "$ssh_terminfo" | builtin command ssh "${ssh_opts[@]}" -o ControlMaster=yes -o ControlPath="$ssh_cpath" -o ControlPersist=60s "$@" '
|
||||
if builtin echo "$ssh_terminfo" | builtin command ssh -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")
|
||||
|
||||
|
@ -108,8 +108,10 @@
|
||||
|
||||
# Configure environment variables for remote session
|
||||
if (str:contains $E:GHOSTTY_SHELL_FEATURES ssh-env) {
|
||||
set ssh-opts = [$@ssh-opts -o "SetEnv COLORTERM=truecolor"]
|
||||
set ssh-opts = [$@ssh-opts -o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION"]
|
||||
set ssh-opts = (conj $ssh-opts
|
||||
-o "SetEnv COLORTERM=truecolor"
|
||||
-o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION"
|
||||
)
|
||||
}
|
||||
|
||||
# Install terminfo on remote host if needed
|
||||
@ -117,88 +119,56 @@
|
||||
var ssh-user = ""
|
||||
var ssh-hostname = ""
|
||||
|
||||
try {
|
||||
# Parse ssh config
|
||||
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]
|
||||
var ssh-key = $parts[0]
|
||||
var ssh-value = $parts[1]
|
||||
if (eq $ssh-key user) {
|
||||
set ssh-user = $ssh-value
|
||||
} elif (eq $ssh-key hostname) {
|
||||
set ssh-hostname = $ssh-value
|
||||
}
|
||||
if (and (not-eq $ssh-user "") (not-eq $ssh-hostname "")) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
# ssh config failed
|
||||
}
|
||||
|
||||
var ssh-target = $ssh-user"@"$ssh-hostname
|
||||
|
||||
if (not-eq $ssh-hostname "") {
|
||||
# Check if terminfo is already cached
|
||||
var ssh-cache-check-success = $false
|
||||
try {
|
||||
external ghostty +ssh-cache --host=$ssh-target >/dev/null 2>&1
|
||||
set ssh-cache-check-success = $true
|
||||
} catch {
|
||||
# cache check failed
|
||||
}
|
||||
|
||||
if $ssh-cache-check-success {
|
||||
if (and (has-external ghostty) (bool ?(external ghostty +ssh-cache --host=$ssh-target >/dev/null 2>&1))) {
|
||||
set ssh-term = "xterm-ghostty"
|
||||
} else {
|
||||
try {
|
||||
external infocmp --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 = ""
|
||||
}
|
||||
} elif (has-external infocmp) {
|
||||
var ssh-terminfo = (external infocmp -0 -x xterm-ghostty 2>/dev/null | slurp)
|
||||
|
||||
if (not-eq $ssh-terminfo "") {
|
||||
echo "Setting up Ghostty terminfo on "$ssh-hostname"..." >&2
|
||||
echo "Setting up xterm-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)
|
||||
}
|
||||
set ssh-cpath = $ssh-cpath-dir"/socket"
|
||||
var 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 '
|
||||
if (bool ?(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 $terminfo-install-success {
|
||||
echo "Terminfo setup complete on "$ssh-hostname"." >&2
|
||||
' 2>/dev/null)) {
|
||||
set ssh-term = "xterm-ghostty"
|
||||
set ssh-opts = [$@ssh-opts -o ControlPath=$ssh-cpath]
|
||||
set ssh-opts = (conj $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
|
||||
@ -206,23 +176,14 @@
|
||||
} else {
|
||||
echo "Warning: Could not generate terminfo data." >&2
|
||||
}
|
||||
} catch {
|
||||
} else {
|
||||
echo "Warning: ghostty command not available for cache management." >&2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 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
|
||||
external E:TERM=$ssh-term ssh $@ssh-opts $@args
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,19 +87,21 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
end
|
||||
|
||||
# SSH Integration
|
||||
if string match -q '*ssh-*' -- "$GHOSTTY_SHELL_FEATURES"
|
||||
set -l features (string split ',' -- "$GHOSTTY_SHELL_FEATURES")
|
||||
if contains ssh-env $features; or contains ssh-terminfo $features
|
||||
function ssh --wraps=ssh --description "SSH wrapper with Ghostty integration"
|
||||
set -l features (string split ',' -- "$GHOSTTY_SHELL_FEATURES")
|
||||
set -l ssh_term "xterm-256color"
|
||||
set -l ssh_opts
|
||||
|
||||
# Configure environment variables for remote session
|
||||
if string match -q '*ssh-env*' -- "$GHOSTTY_SHELL_FEATURES"
|
||||
if contains ssh-env $features
|
||||
set -a ssh_opts -o "SetEnv COLORTERM=truecolor"
|
||||
set -a ssh_opts -o "SendEnv TERM_PROGRAM TERM_PROGRAM_VERSION"
|
||||
end
|
||||
|
||||
# Install terminfo on remote host if needed
|
||||
if string match -q '*ssh-terminfo*' -- "$GHOSTTY_SHELL_FEATURES"
|
||||
if contains ssh-terminfo $features
|
||||
set -l ssh_user
|
||||
set -l ssh_hostname
|
||||
|
||||
@ -122,14 +124,7 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
|
||||
if test -n "$ssh_hostname"
|
||||
# Check if terminfo is already cached
|
||||
set -l ssh_cache_check_success false
|
||||
if command -v ghostty >/dev/null 2>&1
|
||||
if ghostty +ssh-cache --host="$ssh_target" >/dev/null 2>&1
|
||||
set ssh_cache_check_success true
|
||||
end
|
||||
end
|
||||
|
||||
if test "$ssh_cache_check_success" = "true"
|
||||
if command -v ghostty >/dev/null 2>&1; and ghostty +ssh-cache --host="$ssh_target" >/dev/null 2>&1
|
||||
set ssh_term "xterm-ghostty"
|
||||
else if command -v infocmp >/dev/null 2>&1
|
||||
set -l ssh_terminfo
|
||||
@ -139,7 +134,7 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
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
|
||||
echo "Setting up xterm-ghostty terminfo on $ssh_hostname..." >&2
|
||||
|
||||
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"
|
||||
@ -150,7 +145,6 @@ function __ghostty_setup --on-event fish_prompt -d "Setup ghostty integration"
|
||||
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"
|
||||
|
||||
|
@ -276,12 +276,7 @@ _ghostty_deferred_init() {
|
||||
|
||||
if [[ -n "$ssh_hostname" ]]; then
|
||||
# Check if terminfo is already cached
|
||||
local ssh_cache_check_success=false
|
||||
if (( $+commands[ghostty] )); then
|
||||
ghostty +ssh-cache --host="$ssh_target" >/dev/null 2>&1 && ssh_cache_check_success=true
|
||||
fi
|
||||
|
||||
if [[ "$ssh_cache_check_success" == "true" ]]; then
|
||||
if (( $+commands[ghostty] )) && ghostty +ssh-cache --host="$ssh_target" >/dev/null 2>&1; then
|
||||
ssh_term="xterm-ghostty"
|
||||
elif (( $+commands[infocmp] )); then
|
||||
local ssh_terminfo ssh_cpath_dir ssh_cpath
|
||||
@ -289,7 +284,7 @@ _ghostty_deferred_init() {
|
||||
ssh_terminfo=$(infocmp -0 -x xterm-ghostty 2>/dev/null)
|
||||
|
||||
if [[ -n "$ssh_terminfo" ]]; then
|
||||
print "Setting up Ghostty terminfo on $ssh_hostname..." >&2
|
||||
print "Setting up xterm-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"
|
||||
@ -300,7 +295,6 @@ _ghostty_deferred_init() {
|
||||
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")
|
||||
|
||||
|
Reference in New Issue
Block a user