MCPcopy Index your code
hub / github.com/ddev/ddev / FindBashPath

Function FindBashPath

pkg/util/utils.go:248–274  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

246// On Windows we'll need the path to Bash to execute anything.
247// Returns empty string if not found, path if found
248func 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.

Callers 15

processBashHostActionFunction · 0.92
ExecuteMethod · 0.92
ExecOnHostOrServiceMethod · 0.92
TestFindBashPathFunction · 0.92
addCustomCommandsFunction · 0.92
makeHostCmdFunction · 0.92
TestCmdExecFunction · 0.92
share.goFile · 0.92
TestCmdRestartJSONFunction · 0.92

Calls 2

IsWindowsFunction · 0.92
WarningOnceFunction · 0.85

Tested by 8

TestFindBashPathFunction · 0.74
TestCmdExecFunction · 0.74
TestCmdRestartJSONFunction · 0.74
TestMainFunction · 0.74
TestGetActiveAppRootFunction · 0.74
TestCmdSSHFunction · 0.74
TestCmdAutostartFunction · 0.74