more improvements with autocomplete
This commit is contained in:
parent
b658111125
commit
1522a2fef0
35
bash2.go
35
bash2.go
|
@ -143,7 +143,21 @@ func (args) doBashHelp() {
|
|||
*/
|
||||
|
||||
func (pb *Auto) Autocomplete(notsure any, sendthis string) {
|
||||
fmt.Println(sendthis)
|
||||
parts := strings.Split(sendthis, " ")
|
||||
var all []string
|
||||
for _, part := range parts {
|
||||
var found bool
|
||||
for _, s := range os.Args {
|
||||
if s == part {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
all = append(all, part)
|
||||
}
|
||||
fmt.Printf("%s", strings.Join(all, " "))
|
||||
}
|
||||
|
||||
func parseArgv(argname string) *Auto {
|
||||
|
@ -172,7 +186,6 @@ func parseArgv(argname string) *Auto {
|
|||
newauto.Arg1 = os.Args[1]
|
||||
newauto.Partial = os.Args[2]
|
||||
newauto.Arg3 = os.Args[3]
|
||||
newauto.Argv = os.Args[4:]
|
||||
if len(os.Args) < 5 {
|
||||
// the user is doing autocomplete on the command itself
|
||||
newauto.Partial = ""
|
||||
|
@ -180,17 +193,21 @@ func parseArgv(argname string) *Auto {
|
|||
newauto.Argv = []string{""}
|
||||
return newauto
|
||||
}
|
||||
newauto.Argv = os.Args[4:]
|
||||
if newauto.Partial == "''" {
|
||||
newauto.Partial = ""
|
||||
newauto.Cmd = "todo:findme"
|
||||
// set pb.Cmd to the first thing that doesn't have a '-' arg
|
||||
for _, s := range newauto.Argv {
|
||||
if strings.HasPrefix(s, "-") {
|
||||
continue
|
||||
}
|
||||
newauto.Cmd = s
|
||||
break
|
||||
}
|
||||
// set pb.Cmd to the first thing that doesn't have a '-' arg
|
||||
for _, s := range newauto.Argv {
|
||||
if strings.HasPrefix(s, "-") {
|
||||
continue
|
||||
}
|
||||
newauto.Cmd = s
|
||||
break
|
||||
}
|
||||
if newauto.Cmd == "" {
|
||||
newauto.Cmd = strings.Join(newauto.Argv, "BLAH")
|
||||
}
|
||||
return newauto
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue