diff --git a/default/bash/envs b/default/bash/envs index e4763d6c..ac608cb7 100644 --- a/default/bash/envs +++ b/default/bash/envs @@ -16,6 +16,18 @@ export MANPAGER="sh -c 'col -bx | bat -l man -p'" # other non-interactive non-login bash sessions still get OMARCHY_PATH. [ -r /usr/share/omarchy/default/bash/env-bootstrap ] && . /usr/share/omarchy/default/bash/env-bootstrap +# /etc/profile.d/locale.sh is what puts /etc/locale.conf into the environment, +# and it only runs for login shells. Bash started by SSH or herdr's remote +# bridge misses it and lands in the C locale, where printf emits \u/\U escapes +# literally instead of the character. Mirror locale.sh for those sessions. +if [ -z "${LANG:-}" ]; then + [ -r /etc/locale.conf ] && . /etc/locale.conf + LANG="${LANG:-C.UTF-8}" + export LANG LANGUAGE LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ + LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT \ + LC_IDENTIFICATION +fi + case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) export PATH="$PATH:$HOME/.local/bin" ;; diff --git a/test/shell.d/locale-env-test.sh b/test/shell.d/locale-env-test.sh new file mode 100755 index 00000000..5a104a70 --- /dev/null +++ b/test/shell.d/locale-env-test.sh @@ -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"