Skip to content

Commit

Permalink
add executable completion on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
gokcehan committed Jun 28, 2018
1 parent fef99c1 commit e1b6d38
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 3 additions & 2 deletions complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
}
}
Expand Down
4 changes: 4 additions & 0 deletions os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ var (
envShell = os.Getenv("SHELL")
)

var (
envPathExt = os.Getenv("PATHEXT")
)

var (
gDefaultShell = "cmd"
gDefaultSocketProt = "tcp"
Expand Down Expand Up @@ -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
}

0 comments on commit e1b6d38

Please sign in to comment.