elvish/util/search.go
2017-12-19 01:37:52 +00:00

24 lines
505 B
Go

package util
import (
"os"
"path/filepath"
"strings"
)
// DontSearch determines whether the path to an external command should be
// taken literally and not searched.
func DontSearch(exe string) bool {
return exe == ".." || strings.ContainsRune(exe, filepath.Separator)
}
// IsExecutable determines whether path refers to an executable file.
func IsExecutable(path string) bool {
fi, err := os.Stat(path)
if err != nil {
return false
}
fm := fi.Mode()
return !fm.IsDir() && (fm&0111 != 0)
}