Fix bash OSC 7 reporting $HOSTNAME instead of gethostname(2)#277
Merged
Conversation
Bash inherits $HOSTNAME from the environment. Toolbox/container
runtimes export it with a value that disagrees with the kernel
hostname, so emacs' (system-name) — which reads gethostname(2) —
sees a mismatch, ghostel--update-directory classifies the buffer
as remote, and TRAMP fires on every cd. zsh ($HOST) and fish
($(hostname)) read gethostname(2) directly and aren't affected.
Capture the real kernel hostname via ${var@P} on \H (bash 4.4+),
which expands the same value bash uses internally for the \H
prompt escape — sourced from gethostname(2) at startup and not
overridable from the environment. On bash <4.4 the @p transform
is unavailable, so fall back to $HOSTNAME (pre-fix behavior).
Fixes #276.
aaffd87 to
be0f53f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
etc/shell/ghostel.bash) emitted$HOSTNAMEin the OSC 7 directory-tracking sequence.$HOSTNAMEis inherited from the parent environment — toolbox/container runtimes export it with a value that disagrees withgethostname(2). Emacs'system-namereadsgethostname(2)directly, so the host strings didn't match,ghostel--update-directorymisclassified the buffer as remote, and TRAMP fired on everycd. zsh ($HOST) and fish ((hostname)) readgethostname(2)directly and aren't affected.${var@P}on\H(bash 4.4+) — same value bash uses internally for the\HPS1 escape, sourced fromgethostname(2)at startup and not overridable from the environment. Zero forks, no external binary dependency.@Ptransform is unavailable (it produces abad substitutionerror and leaves the variable as the literal\H, which would actually break OSC 7 worse than the original bug). Guard withBASH_VERSINFOand fall back to$HOSTNAME— pre-tramp getting triggered inside local fedora-toolbox container #276 behavior for those users, no regression.bash --noprofile --norcsubprocess with a poisonedHOSTNAME=…, calls__ghostel_osc7, and asserts the emitted host passesghostel--local-host-p— the same predicate the production code applies inghostel--update-directory.Fixes #276.
Test plan
make -j4 allpasses (382 tests).ghostel-test-bash-osc7-ignores-env-hostnamepasses against the patched bash integration.main's bash integration (confirms it exercises the bug, not just any assertion).bash -n etc/shell/ghostel.bashclean on both modern bash (5.x) and/bin/bash3.2.HOSTNAME:HOSTNAME=lying-fake bash -c 'source etc/shell/ghostel.bash; echo $__ghostel_host'reports the real kernel hostname on bash 4.4+.