diff --git a/complete.go b/complete.go index 484839d6..f91a6764 100644 --- a/complete.go +++ b/complete.go @@ -134,7 +134,7 @@ func matchWord(s string, words []string) (matches []string, longest string) { func matchExec(s string) (matches []string, longest string) { var words []string - paths := strings.Split(envPath, ":") + paths := strings.Split(envPath, string(filepath.ListSeparator)) for _, p := range paths { if _, err := os.Stat(p); os.IsNotExist(err) { @@ -157,10 +157,11 @@ func matchExec(s string) (matches []string, longest string) { continue } - if !f.Mode().IsRegular() || f.Mode()&0111 == 0 { + if !f.Mode().IsRegular() || !isExecutable(f) { continue } + log.Print(f.Name()) words = append(words, f.Name()) } } diff --git a/os.go b/os.go index 4299e797..8f9fe992 100644 --- a/os.go +++ b/os.go @@ -129,3 +129,7 @@ func setDefaults() { func moveCursor(y, x int) { fmt.Printf("\033[%d;%dH", y, x) } + +func isExecutable(f os.FileInfo) bool { + return f.Mode()&0111 != 0 +} diff --git a/os_windows.go b/os_windows.go index ba658c7d..bcfdc39b 100644 --- a/os_windows.go +++ b/os_windows.go @@ -16,6 +16,10 @@ var ( envShell = os.Getenv("SHELL") ) +var ( + envPathExt = os.Getenv("PATHEXT") +) + var ( gDefaultShell = "cmd" gDefaultSocketProt = "tcp" @@ -109,3 +113,14 @@ func moveCursor(y, x int) { // TODO: implement return } + +func isExecutable(f os.FileInfo) bool { + exts := strings.Split(envPathExt, string(filepath.ListSeparator)) + for _, e := range exts { + if strings.HasSuffix(strings.ToLower(f.Name()), strings.ToLower(e)) { + log.Print(f.Name(), e) + return true + } + } + return false +}