mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-20 11:07:38 +03:00
Allow specifying the paths to search in Which()
This commit is contained in:
parent
97b9572bec
commit
06bfa671d9
@ -13,15 +13,18 @@ import (
|
||||
|
||||
var _ = fmt.Print
|
||||
|
||||
func Which(cmd string) string {
|
||||
func Which(cmd string, paths ...string) string {
|
||||
if strings.Contains(cmd, string(os.PathSeparator)) {
|
||||
return ""
|
||||
}
|
||||
path := os.Getenv("PATH")
|
||||
if path == "" {
|
||||
return ""
|
||||
if len(paths) == 0 {
|
||||
path := os.Getenv("PATH")
|
||||
if path == "" {
|
||||
return ""
|
||||
}
|
||||
paths = strings.Split(path, string(os.PathListSeparator))
|
||||
}
|
||||
for _, dir := range strings.Split(path, string(os.PathListSeparator)) {
|
||||
for _, dir := range paths {
|
||||
q := filepath.Join(dir, cmd)
|
||||
if unix.Access(q, unix.X_OK) == nil {
|
||||
s, err := os.Stat(q)
|
||||
|
Loading…
Reference in New Issue
Block a user