FindBashPath returns the PATH to Bash on any system on Windows preferring git-bash On Windows we'll need the path to Bash to execute anything. Returns empty string if not found, path if found
()
| 246 | // On Windows we'll need the path to Bash to execute anything. |
| 247 | // Returns empty string if not found, path if found |
| 248 | func FindBashPath() string { |
| 249 | if !nodeps.IsWindows() { |
| 250 | return "bash" |
| 251 | } |
| 252 | |
| 253 | // Check for user-local Git Bash installation first (installed for current user only) |
| 254 | // This takes precedence over system-wide installations |
| 255 | if localAppData := os.Getenv("LOCALAPPDATA"); localAppData != "" { |
| 256 | userLocalBashPath := filepath.Join(localAppData, `Programs\Git\bin\bash.exe`) |
| 257 | if _, err := os.Stat(userLocalBashPath); err == nil { |
| 258 | return userLocalBashPath |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | // Check for system-wide Git Bash installation using PROGRAMFILES environment variable |
| 263 | // This works even if Program Files is on a different drive |
| 264 | if programFiles := os.Getenv("PROGRAMFILES"); programFiles != "" { |
| 265 | systemWideBashPath := filepath.Join(programFiles, `Git\bin\bash.exe`) |
| 266 | if _, err := os.Stat(systemWideBashPath); err == nil { |
| 267 | return systemWideBashPath |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Not found - don't search PATH as it may return WSL bash which won't work |
| 272 | WarningOnce("Git Bash is not installed in standard locations, so some features like custom commands may not work correctly") |
| 273 | return "" |
| 274 | } |
| 275 | |
| 276 | // ElapsedTime is an easy way to report how long something took. |
| 277 | // It returns an anonymous function that, when called, will return the elapsed seconds. |