@@ -3,7 +3,7 @@ package ishell
33import (
44 "strings"
55
6- "github.com/flynn-archive/go-shlex"
6+ shlex "github.com/flynn-archive/go-shlex"
77)
88
99type iCompleter struct {
@@ -23,14 +23,12 @@ func (ic iCompleter) Do(line []rune, pos int) (newLine [][]rune, length int) {
2323 words = strings .Fields (string (line ))
2424 }
2525
26- var cWords []string
2726 prefix := ""
2827 if len (words ) > 0 && pos > 0 && line [pos - 1 ] != ' ' {
2928 prefix = words [len (words )- 1 ]
30- cWords = ic .getWords (words [:len (words )- 1 ])
31- } else {
32- cWords = ic .getWords (words )
29+ words = words [:len (words )- 1 ]
3330 }
31+ cWords := ic .getWords (words , prefix )
3432
3533 var suggestions [][]rune
3634 for _ , w := range cWords {
@@ -44,16 +42,23 @@ func (ic iCompleter) Do(line []rune, pos int) (newLine [][]rune, length int) {
4442 return suggestions , len (prefix )
4543}
4644
47- func (ic iCompleter ) getWords (w []string ) (s []string ) {
45+ func (ic iCompleter ) getWords (w []string , prefix string ) (s []string ) {
4846 cmd , args := ic .cmd .FindCmd (w )
4947 if cmd == nil {
5048 cmd , args = ic .cmd , w
5149 }
5250 if cmd .Completer != nil {
53- return cmd .Completer (args )
51+ return cmd .Completer (cmd , args , prefix )
5452 }
55- for k := range cmd .children {
53+ for k , child := range cmd .children {
5654 s = append (s , k )
55+
56+ // add aliases when command name won't match
57+ if ! strings .HasPrefix (k , prefix ) {
58+ for _ , a := range child .Aliases {
59+ s = append (s , a )
60+ }
61+ }
5762 }
5863 return
5964}
0 commit comments