diff --git a/tools/cmd/ssh/utils.go b/tools/cmd/ssh/utils.go index ef2514260..e33e3eee5 100644 --- a/tools/cmd/ssh/utils.go +++ b/tools/cmd/ssh/utils.go @@ -22,7 +22,7 @@ var SSHExe = (&utils.Once[string]{Run: func() string { if ans != "" { return ans } - ans = utils.Which("ssh", "/usr/local/bin", "/opt/bin", "/opt/homebrew/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin") + ans = utils.Which("ssh", utils.DefaultExeSearchPaths()...) if ans == "" { ans = "ssh" } diff --git a/tools/utils/which.go b/tools/utils/which.go index 1a4c194d9..209f83d6d 100644 --- a/tools/utils/which.go +++ b/tools/utils/which.go @@ -13,6 +13,16 @@ import ( var _ = fmt.Print +var DefaultExeSearchPaths = (&Once[[]string]{Run: func() []string { + candidates := [...]string{"/usr/local/bin", "/opt/bin", "/opt/homebrew/bin", "/usr/bin", "/bin", "/usr/sbin", "/sbin"} + ans := make([]string, 0, len(candidates)) + for _, x := range candidates { + if s, err := os.Stat(x); err != nil && s.IsDir() { + } + } + return ans +}}).Get + func Which(cmd string, paths ...string) string { if strings.Contains(cmd, string(os.PathSeparator)) { return ""