Give non-login shells the system locale

/etc/profile.d/locale.sh only runs for login shells, so bash started by
SSH or herdr's remote bridge ran in the C locale, where printf emits
\u/\U escapes literally instead of the character.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-08-10 05:58:56 -07:00
co-authored by Claude Opus 5
parent 7633d8dee4
commit 6d7826d635
2 changed files with 40 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/bin/bash
set -euo pipefail
source "$(dirname "$0")/base-test.sh"
envs="$ROOT/default/bash/envs"
# Non-login bash (SSH, herdr's remote bridge) never sources
# /etc/profile.d/locale.sh, so without this the shell runs in the C locale.
lang=$(env -u LANG bash -c 'source "$1"; printf "%s" "$LANG"' bash "$envs")
[[ -n $lang ]] || fail "bash env sets a locale when none is inherited"
pass "bash env sets a locale when none is inherited"
[[ ${lang,,} == *utf-8 || ${lang,,} == *utf8 ]] ||
fail "bash env picks a UTF-8 locale" "actual: $lang"
pass "bash env picks a UTF-8 locale"
lang=$(LANG=en_DK.UTF-8 bash -c 'source "$1"; printf "%s" "$LANG"' bash "$envs")
[[ $lang == "en_DK.UTF-8" ]] || fail "bash env preserves the inherited locale" "actual: $lang"
pass "bash env preserves the inherited locale"
# The symptom that started this: bash only converts \u/\U escapes above 0x7f
# when the locale's charset can encode them, so default/bash/aliases prints the
# zoxide folder glyph as a literal "\U000F17A9" in the C locale.
glyph=$(env -u LANG bash -c 'source "$1"; printf "\U000F17A9"' bash "$envs")
[[ $glyph != *'\U'* ]] || fail "bash env locale renders unicode escapes" "actual: $glyph"
pass "bash env locale renders unicode escapes"