File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22set -e
33export -n CDPATH
4- export LC_ALL=C # boost grep performance by disabling unicode
4+
5+ # Save original LC_ALL to restore later
6+ GOENV_ORIGINAL_LC_ALL=" ${LC_ALL:- } "
7+
8+ # Temporarily set LC_ALL=C to boost grep performance by disabling unicode
9+ export LC_ALL=C
510
611if [ " $1 " = " --debug" ]; then
712 export GOENV_DEBUG=1
@@ -24,6 +29,15 @@ abort() {
2429 exit 1
2530}
2631
32+ # Restore original LC_ALL before executing commands
33+ restore_lc_all () {
34+ if [ -n " $GOENV_ORIGINAL_LC_ALL " ]; then
35+ export LC_ALL=" $GOENV_ORIGINAL_LC_ALL "
36+ else
37+ unset LC_ALL
38+ fi
39+ }
40+
2741if enable -f " ${BASH_SOURCE%/* } " /../libexec/goenv-realpath.dylib realpath 2> /dev/null; then
2842 abs_dirname () {
2943 local path=" $( realpath " $1 " ) "
@@ -121,13 +135,16 @@ case "$command" in
121135 } | abort
122136 ;;
123137-v | --version)
138+ restore_lc_all
124139 exec goenv---version
125140 ;;
126141-h | --help)
142+ restore_lc_all
127143 exec goenv-help
128144 ;;
129145# NOTE: Provide goenv completions
130146--complete)
147+ restore_lc_all
131148 exec goenv-commands
132149 ;;
133150* )
@@ -149,8 +166,10 @@ case "$command" in
149166 fi
150167
151168 if [ " $1 " = --help ]; then
169+ restore_lc_all
152170 exec goenv-help " $command "
153171 else
172+ restore_lc_all
154173 exec " $command_path " " $@ "
155174 fi
156175 ;;
Original file line number Diff line number Diff line change @@ -350,3 +350,36 @@ $GOENV_ROOT/versions/1.12.0
350350/tmp/goenv/example/1.12.0
351351OUT
352352}
353+
354+ @test " preserves LC_ALL environment variable when executing commands" {
355+ create_version " 1.12.0"
356+ create_executable " 1.12.0" " go-lc" << SH
357+ #!$BASH
358+ echo "LC_ALL=\$ LC_ALL"
359+ SH
360+
361+ LC_ALL=en_US.UTF-8 GOENV_VERSION=1.12.0 PATH=${GOENV_TEST_DIR} :${PATH} run goenv-exec go-lc
362+
363+ assert_success_out << OUT
364+ LC_ALL=en_US.UTF-8
365+ OUT
366+ }
367+
368+ @test " LC_ALL remains unset if it was not set before" {
369+ create_version " 1.12.0"
370+ create_executable " 1.12.0" " go-lc" << SH
371+ #!$BASH
372+ if [ -z "\$ LC_ALL" ]; then
373+ echo "LC_ALL is unset"
374+ else
375+ echo "LC_ALL=\$ LC_ALL"
376+ fi
377+ SH
378+
379+ unset LC_ALL
380+ GOENV_VERSION=1.12.0 PATH=${GOENV_TEST_DIR} :${PATH} run goenv-exec go-lc
381+
382+ assert_success_out << OUT
383+ LC_ALL is unset
384+ OUT
385+ }
You can’t perform that action at this time.
0 commit comments