Skip to content

Set TERM via on-remote infocmp probe, not env propagation#232

Merged
dakra merged 1 commit into
mainfrom
fix/tramp-remote-term-probe
May 4, 2026
Merged

Set TERM via on-remote infocmp probe, not env propagation#232
dakra merged 1 commit into
mainfrom
fix/tramp-remote-term-probe

Conversation

@dakra
Copy link
Copy Markdown
Owner

@dakra dakra commented May 4, 2026

Summary

Fixes #224 (again). The previous fix (6a6101a) rebound tramp-terminal-type, but that variable is only consulted by tramp-handle-make-process (the generic handler). The ssh-method path most users hit (tramp-sh-handle-make-process) ignores it entirely. Plus, when the local default-toplevel process-environment already had TERM=xterm-ghostty (e.g. Emacs launched from ghostty), tramp-local-environment-variable-p stripped ghostel's pushed TERM as "ambient" — and the remote shell inherited TERM=dumb from TRAMP's connection shell, disabling readline/ZLE/fish line editing.

The new approach moves the TERM decision into the per-spawn /bin/sh -c wrapper so the remote shell decides after env propagation:

  • Probe via infocmp xterm-ghostty. On hit, advertise ghostty (TERM/TERM_PROGRAM/TERM_PROGRAM_VERSION); on miss, fall back to xterm-256color so echo works.
  • When ~/.local/share/ghostel/terminfo holds the bundled entry, prepend it to TERMINFO_DIRS before the probe — manual setups can co-locate terminfo with the shell scripts (no tic, no ~/.terminfo).
  • The local on-disk TERMINFO path is no longer pushed to the remote (it pointed at a directory the remote couldn't read and per terminfo(5) was suppressing system lookups).
  • tramp-terminal-type let-binding from 6a6101a is removed.

README "Option 2: Manual setup" updated with the one-shot install recipe (shell scripts + co-located terminfo in one mkdir + scp burst).

Test plan

  • make -j4 all green (219/219 elisp, 47/47 native, lint, build)
  • Wrapper-script POSIX portability (dash, bash, zsh, ksh)
  • TRAMP-quoting roundtrip verified — backslash-escaped tildes survive the connection-shell strip step, inner /bin/sh -c sees literal ~/... and expands correctly
  • Convention-path detection verified end-to-end via HOME override + tramp-shell-quote-argument simulation
  • New ghostel-test-remote-term-preamble and ghostel-test-spawn-pty-uses-remote-term-preamble cover the wrapper shape, the env-doesn't-leak-TERM-or-TERMINFO contract, and the load-bearing order (TERMINFO_DIRS prepend BEFORE the infocmp probe)
  • Live verification on a real TRAMP /ssh: session (manual, since TRAMP isn't covered by the automated test suite)

Behavioral matrix

Setup Before After
No integration, nothing on remote TERM=dumb → no echo TERM=xterm-256color → echo works
ghostel-tramp-shell-integration t works unchanged (TERMINFO env reaches the probe)
Manual install via ~/.terminfo broken (bogus local TERMINFO suppressed lookup) works (probe finds it)
Manual install via co-located ~/.local/share/ghostel/terminfo n/a works (newly supported)

The previous fix (6a6101a) rebound `tramp-terminal-type', which
only takes effect on the generic `tramp-handle-make-process'
path; the ssh-method path (`tramp-sh-handle-make-process')
ignores it entirely.  In addition, when the local default
top-level `process-environment' already has TERM=xterm-ghostty
(e.g. Emacs launched from ghostty), `tramp-local-environment-
variable-p' strips ghostel's pushed TERM as "ambient", and the
remote shell inherits TERM=dumb from TRAMP's connection shell —
disabling readline/ZLE/fish line editing on the remote.

Move the decision into the per-spawn `/bin/sh -c' wrapper so the
remote shell decides after env propagation:
- probe via `infocmp xterm-ghostty'; on success advertise ghostty,
  otherwise fall back to xterm-256color so echo works;
- when ~/.local/share/ghostel/terminfo holds the bundled entry,
  prepend it to TERMINFO_DIRS first so manual setups can co-locate
  terminfo with the shell-integration scripts (no `tic', no
  ~/.terminfo);
- the local TERMINFO path is no longer pushed to the remote — it
  pointed at a directory the remote couldn't read and (per
  terminfo(5)) suppressed system lookups.

README "Option 2: Manual setup" updated with the one-shot install
recipe (shell scripts + co-located terminfo in one mkdir+scp burst).

Closes #224 again.
@dakra dakra force-pushed the fix/tramp-remote-term-probe branch from 8d8cdbc to a026bbd Compare May 4, 2026 09:02
@dakra dakra merged commit a026bbd into main May 4, 2026
37 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tramp issues

1 participant