mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-10 03:46:34 +00:00
refactor: replace ghostty wrapper with proper CLI actions for terminfo cache management
- Add +list-ssh-cache and +clear-ssh-cache CLI actions - Remove ghostty() wrapper functions from all shell integrations - Improve variable naming in shell scripts for readability Addresses @00-kat's feedback about CLI discoverability and naming consistency. The new CLI actions follow established Ghostty patterns and are discoverable via `ghostty --help`, while maintaining clean separation of concerns between shell logic and cache management.
This commit is contained in:
@@ -100,19 +100,11 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then
|
||||
|
||||
if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-terminfo ]]; then
|
||||
readonly _CACHE="${GHOSTTY_RESOURCES_DIR}/shell-integration/shared/ghostty-ssh-cache"
|
||||
# If 'ssh-terminfo' flag is enabled, wrap ghostty to provide cache management commands
|
||||
ghostty() {
|
||||
case "$1" in
|
||||
ssh-cache-list) "$_CACHE" list ;;
|
||||
ssh-cache-clear) "$_CACHE" clear ;;
|
||||
*) builtin command ghostty "$@" ;;
|
||||
esac
|
||||
}
|
||||
fi
|
||||
|
||||
# SSH wrapper
|
||||
ssh() {
|
||||
local e=() o=() c=() # Removed 't' from here
|
||||
local env=() opts=() ctrl=()
|
||||
|
||||
# Set up env vars first so terminfo installation inherits them
|
||||
if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then
|
||||
@@ -123,35 +115,35 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then
|
||||
)
|
||||
for v in "${vars[@]}"; do
|
||||
builtin export "${v?}"
|
||||
o+=(-o "SendEnv ${v%=*}" -o "SetEnv $v")
|
||||
opts+=(-o "SendEnv ${v%=*}" -o "SetEnv $v")
|
||||
done
|
||||
fi
|
||||
|
||||
# Install terminfo if needed, reuse control connection for main session
|
||||
if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-terminfo ]]; then
|
||||
# Get target (only when needed for terminfo)
|
||||
builtin local t
|
||||
t=$(builtin command ssh -G "$@" 2>/dev/null | awk '/^(user|hostname) /{print $2}' | paste -sd'@')
|
||||
builtin local target
|
||||
target=$(builtin command ssh -G "$@" 2>/dev/null | awk '/^(user|hostname) /{print $2}' | paste -sd'@')
|
||||
|
||||
if [[ -n "$t" ]] && "$_CACHE" chk "$t"; then
|
||||
e+=(TERM=xterm-ghostty)
|
||||
if [[ -n "$target" ]] && "$_CACHE" chk "$target"; then
|
||||
env+=(TERM=xterm-ghostty)
|
||||
elif builtin command -v infocmp >/dev/null 2>&1; then
|
||||
builtin local ti
|
||||
ti=$(infocmp -x xterm-ghostty 2>/dev/null) || builtin echo "Warning: xterm-ghostty terminfo not found locally." >&2
|
||||
if [[ -n "$ti" ]]; then
|
||||
builtin local tinfo
|
||||
tinfo=$(infocmp -x xterm-ghostty 2>/dev/null) || builtin echo "Warning: xterm-ghostty terminfo not found locally." >&2
|
||||
if [[ -n "$tinfo" ]]; then
|
||||
builtin echo "Setting up Ghostty terminfo on remote host..." >&2
|
||||
builtin local cp
|
||||
cp="/tmp/ghostty-ssh-$USER-$RANDOM-$(date +%s)"
|
||||
case $(builtin echo "$ti" | builtin command ssh "${o[@]}" -o ControlMaster=yes -o ControlPath="$cp" -o ControlPersist=60s "$@" '
|
||||
builtin local cpath
|
||||
cpath="/tmp/ghostty-ssh-$USER-$RANDOM-$(date +%s)"
|
||||
case $(builtin echo "$tinfo" | builtin command ssh "${opts[@]}" -o ControlMaster=yes -o ControlPath="$cpath" -o ControlPersist=60s "$@" '
|
||||
infocmp xterm-ghostty >/dev/null 2>&1 && echo OK && exit
|
||||
command -v tic >/dev/null 2>&1 || { echo NO_TIC; exit 1; }
|
||||
mkdir -p ~/.terminfo 2>/dev/null && tic -x - 2>/dev/null && echo OK || echo FAIL
|
||||
') in
|
||||
OK)
|
||||
builtin echo "Terminfo setup complete." >&2
|
||||
[[ -n "$t" ]] && "$_CACHE" add "$t"
|
||||
e+=(TERM=xterm-ghostty)
|
||||
c+=(-o "ControlPath=$cp")
|
||||
[[ -n "$target" ]] && "$_CACHE" add "$target"
|
||||
env+=(TERM=xterm-ghostty)
|
||||
ctrl+=(-o "ControlPath=$cpath")
|
||||
;;
|
||||
*) builtin echo "Warning: Failed to install terminfo." >&2 ;;
|
||||
esac
|
||||
@@ -163,14 +155,14 @@ if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-(env|terminfo) ]]; then
|
||||
|
||||
# Fallback TERM only if terminfo didn't set it
|
||||
if [[ "$GHOSTTY_SHELL_FEATURES" =~ ssh-env ]]; then
|
||||
[[ $TERM == xterm-ghostty && ! " ${e[*]} " =~ " TERM=" ]] && e+=(TERM=xterm-256color)
|
||||
[[ $TERM == xterm-ghostty && ! " ${env[*]} " =~ " TERM=" ]] && env+=(TERM=xterm-256color)
|
||||
fi
|
||||
|
||||
# Execute
|
||||
if [[ ${#e[@]} -gt 0 ]]; then
|
||||
env "${e[@]}" ssh "${o[@]}" "${c[@]}" "$@"
|
||||
if [[ ${#env[@]} -gt 0 ]]; then
|
||||
env "${env[@]}" ssh "${opts[@]}" "${ctrl[@]}" "$@"
|
||||
else
|
||||
builtin command ssh "${o[@]}" "${c[@]}" "$@"
|
||||
builtin command ssh "${opts[@]}" "${ctrl[@]}" "$@"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
Reference in New Issue
Block a user