Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 20, 2025

goenv was setting export LC_ALL=C globally to optimize grep performance, but this leaked to all child processes executed through shims, overwriting users' locale settings and breaking applications that depend on proper locale configuration (e.g., TUI apps, Unicode handling).

Changes

libexec/goenv

  • Capture original LC_ALL value at script startup
  • Add restore_lc_all() function to restore original value (or unset if not previously set)
  • Call restore_lc_all() before all exec statements to isolate LC_ALL=C to the goenv process only

test/goenv-exec.bats

  • Add test verifying LC_ALL is preserved when set
  • Add test verifying LC_ALL remains unset when not previously set

Impact

The fix preserves LC_ALL=C for goenv's internal grep operations while ensuring child processes inherit the user's original locale settings.

# Before: LC_ALL was always C in child processes
$ LC_ALL=en_US.UTF-8 goenv exec go run main.go
LC_ALL=C

# After: LC_ALL is preserved
$ LC_ALL=en_US.UTF-8 goenv exec go run main.go
LC_ALL=en_US.UTF-8
Original prompt

This section details on the original issue you should resolve

<issue_title>goenv resets LC_ALL env var which breaks running and developing TUI apps</issue_title>
<issue_description>Reproduce:

$ goenv install 1.24.2
Downloading go1.24.2.darwin-arm64.tar.gz...
-> go1.24.2.darwin-arm64.tar.gz
######################################################################### 100.0%
Installing Go Darwin arm 1.24.2...
Installed Go Darwin arm 1.24.2 to /Users/thommeo/.goenv/versions/1.24.2

$ cat main.go
package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Printf("LC_ALL=%s", os.Getenv("LC_ALL"))
}

$ which go
/opt/homebrew/bin/go

$ echo $LC_ALL
en_US.UTF-8

$ go run main.go
LC_ALL=en_US.UTF-8

$ GOENV_PATH_ORDER=front eval "$(goenv init -)"

$ which go
/Users/username/.goenv/shims/go

$ go version
go version go1.25.4 darwin/arm64

$ goenv shell 1.24.2

$ go version
go version go1.24.2 darwin/arm64

# Here is the problem: the LC_ALL variable is lost when using go run through goenv
$ go run main.go
LC_ALL=C

$ LC_ALL=en_US.UTF-8 go run main.go
LC_ALL=C

# It works when built
$ go build -o main main.go && ./main
LC_ALL=en_US.UTF-8

# it works when running the binary directly
$ goenv which go
/Users/username/.goenv/versions/1.24.2/bin/go

$ ~/.goenv/versions/1.24.2/bin/go run main.go
LC_ALL=en_US.UTF-8

# it doesn't work when running through goenv shims
$ ~/.goenv/shims/go run main.go
LC_ALL=C

$ goenv version
1.24.2 (set by GOENV_VERSION environment variable)

$ echo $LC_ALL
en_US.UTF-8

$ env | grep LC_ALL
LC_ALL=en_US.UTF-8

$ echo $SHELL
/bin/bash

$ bash --version
GNU bash, version 5.3.3(1)-release (aarch64-apple-darwin24.4.0)
Copyright (C) 2025 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
```</issue_description>

<agent_instructions>Please read through the issue and discover why LC_ALL is being overwritten by goenv</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: ChronosMasterOfAllTime <28963807+ChronosMasterOfAllTime@users.noreply.github.com>
@github-actions github-actions bot added the bug label Nov 20, 2025
Copilot AI changed the title [WIP] Fix goenv resetting LC_ALL environment variable Fix LC_ALL being overwritten by goenv, breaking TUI apps and locale-dependent programs Nov 20, 2025
@ChronosMasterOfAllTime ChronosMasterOfAllTime marked this pull request as ready for review November 20, 2025 04:28
@ChronosMasterOfAllTime ChronosMasterOfAllTime merged commit fe8d75e into master Nov 20, 2025
8 of 9 checks passed
@ChronosMasterOfAllTime ChronosMasterOfAllTime deleted the copilot/fix-goenv-lc-all-variable branch November 20, 2025 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

goenv resets LC_ALL env var which breaks running and developing TUI apps

2 participants