This commit is contained in:
Kovid Goyal 2023-03-05 13:41:36 +05:30
parent c88a171b28
commit a0d30f4dd8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 1 deletions

View File

@ -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"
}

View File

@ -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 ""