mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-20 02:57:19 +03:00
DRYer
This commit is contained in:
parent
c88a171b28
commit
a0d30f4dd8
@ -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"
|
||||
}
|
||||
|
@ -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 ""
|
||||
|
Loading…
Reference in New Issue
Block a user