diff --git a/tests/test-shell-rc.sh b/tests/test-shell-rc.sh index b4359bf..7060760 100755 --- a/tests/test-shell-rc.sh +++ b/tests/test-shell-rc.sh @@ -58,6 +58,25 @@ if command -v zsh >/dev/null 2>&1; then (( \$+functions[_dotfiles_comp_globdots] )) && print ' hook-left' || print ' hook-gone' ")" expect "globdots survives a later compinit; one-shot hook removes itself" "globdots hook-gone" "$actual" + + # TERM fallback: a fake infocmp makes "terminfo entry known / unknown" + # independent of the terminfo database of the host running the test. + mkdir -p "$WORK/infocmp-known" "$WORK/infocmp-unknown" + printf '#!/bin/sh\nexit 0\n' > "$WORK/infocmp-known/infocmp" + printf '#!/bin/sh\nexit 1\n' > "$WORK/infocmp-unknown/infocmp" + chmod +x "$WORK/infocmp-known/infocmp" "$WORK/infocmp-unknown/infocmp" + term_after_rc() { # + PATH="$1:$PATH" TERM="$2" zsh -f -c ". '$DOTFILES/zsh/zshrc.zsh' 2>/dev/null; print -rn -- \"\$TERM\"" + } + + expect "unknown ghostty terminfo falls back to xterm-256color" \ + "xterm-256color" "$(term_after_rc "$WORK/infocmp-unknown" xterm-ghostty)" + expect "known ghostty terminfo leaves TERM unchanged" \ + "xterm-ghostty" "$(term_after_rc "$WORK/infocmp-known" xterm-ghostty)" + expect "unknown non-ghostty terminfo leaves TERM unchanged" \ + "xterm-kitty" "$(term_after_rc "$WORK/infocmp-unknown" xterm-kitty)" + expect "empty TERM defaults to xterm-256color" \ + "xterm-256color" "$(term_after_rc "$WORK/infocmp-known" "")" else echo ">> zsh not installed - zsh tests skipped" fi diff --git a/zsh/zshrc.zsh b/zsh/zshrc.zsh index bb50ddf..b9e6742 100644 --- a/zsh/zshrc.zsh +++ b/zsh/zshrc.zsh @@ -16,6 +16,12 @@ export TERM=${TERM:-xterm-256color} +# Hosts without Ghostty's terminfo (e.g. over SSH) cannot resolve xterm-ghostty; +# fall back so curses programs and line editing keep working. +if [[ "$TERM" == *ghostty* ]] && ! infocmp "$TERM" >/dev/null 2>&1; then + export TERM=xterm-256color +fi + # nvim as the standard editor if command -v nvim >/dev/null 2>&1; then export VISUAL=nvim