mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 02:57:52 +08:00
25 lines
541 B
Go
25 lines
541 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) ||
|
|
strings.ContainsRune(exe, '/')
|
|
}
|
|
|
|
// 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)
|
|
}
|