on main help sign in
fix: only enable built-in core utils by default on windows

Or we risk making them failing on other platforms due to incompatibilities. Fixes #1341

commit569044c5a03f1be9313f39f27ccae5b58f46bafa authorAndrey Nering <andreynering@users.noreply.github.com> dateThu 30 Oct 2025, 16:35 (1 year ago) parenta885da8
2 files changed+30−1
internal/shell/coreutils.go+19 internal/shell/shell.go+11−1
internal/shell/coreutils.gonew file+19
@@ -0,0 +1,19 @@
1+package shell
2+
3+import (
4+ "os"
5+ "runtime"
6+ "strconv"
7+)
8+
9+var useGoCoreUtils bool
10+
11+func init() {
12+ // If CRUSH_CORE_UTILS is set to either true or false, respect that.
13+ // By default, enable on Windows only.
14+ if v, err := strconv.ParseBool(os.Getenv("CRUSH_CORE_UTILS")); err == nil {
15+ useGoCoreUtils = v
16+ } else {
17+ useGoCoreUtils = runtime.GOOS == "windows"
18+ }
19+}
internal/shell/shell.go+11−1
@@ -241,7 +241,7 @@ func (s *Shell) execPOSIX(ctx context.Context, command string) (string, string,
241241 interp.Interactive(false),
242242 interp.Env(expand.ListEnviron(s.env...)),
243243 interp.Dir(s.cwd),
244− interp.ExecHandlers(s.blockHandler(), coreutils.ExecHandler),
244+ interp.ExecHandlers(s.execHandlers()...),
245245 )
246246 if err != nil {
247247 return "", "", fmt.Errorf("could not run command: %w", err)
@@ -257,6 +257,16 @@ func (s *Shell) execPOSIX(ctx context.Context, command string) (string, string,
257257 return stdout.String(), stderr.String(), err
258258}
259259
260+func (s *Shell) execHandlers() []func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc {
261+ handlers := []func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc{
262+ s.blockHandler(),
263+ }
264+ if useGoCoreUtils {
265+ handlers = append(handlers, coreutils.ExecHandler)
266+ }
267+ return handlers
268+}
269+
260270// IsInterrupt checks if an error is due to interruption
261271func IsInterrupt(err error) bool {
262272 return errors.Is(err, context.Canceled) ||