Skip to main content

Module EnhanceShellEnvironment

Module EnhanceShellEnvironment 

Source
Expand description

macOS / Linux GUI launches (Finder double-click, Dock, Spotlight, open <bundle>.app) hand the app a minimal environment: PATH=/usr/bin:/bin:/usr/sbin:/sbin, no NVM_DIR, no HOMEBREW_PREFIX, no JAVA_HOME, …

That breaks every child process Mountain or its extensions spawn:

  • Cocoon’s node binary can’t find Homebrew installs (/opt/homebrew/bin, /usr/local/bin).
  • Language servers (rust-analyzer, gopls, pyright) probe PATH and fail to launch.
  • Git extensions invoking git fall back to /usr/bin/git (Apple’s ancient stock copy) instead of the Homebrew one.

VS Code, Atom, and most other Electron editors solve this by spawning the user’s interactive shell with -ilc env once at boot and merging the result into the process environment. We do the same here.

Skipped when:

  • The launcher is already a TTY (the user invoked from a terminal - PATH is already correct).
  • Walk=0 (matches the existing knob users may rely on).
  • The shell probe fails or times out (best-effort; never fatal).

Functions§

Fn
Run $SHELL -ilc env and merge novel keys into std::env. Existing values win - never clobber an env var the parent process explicitly set (especially PATH if the user passed one). Caller is expected to invoke this exactly once during boot, before any child process is spawned.
IsPortableEnvName 🔒
Reject keys with characters outside the portable POSIX set so a hostile rc-file can’t sneak shell metacharacters into our env via a crafted Key= line. Standard env-var names are [A-Za-z_][A-Za-z0-9_]*; anything else is dropped silently.
IsTty 🔒