more improvements with autocomplete

This commit is contained in:
Jeff Carr 2025-09-17 22:36:20 -05:00
parent b658111125
commit 1522a2fef0
1 changed files with 26 additions and 9 deletions

View File

@ -143,7 +143,21 @@ func (args) doBashHelp() {
*/ */
func (pb *Auto) Autocomplete(notsure any, sendthis string) { 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 { func parseArgv(argname string) *Auto {
@ -172,7 +186,6 @@ func parseArgv(argname string) *Auto {
newauto.Arg1 = os.Args[1] newauto.Arg1 = os.Args[1]
newauto.Partial = os.Args[2] newauto.Partial = os.Args[2]
newauto.Arg3 = os.Args[3] newauto.Arg3 = os.Args[3]
newauto.Argv = os.Args[4:]
if len(os.Args) < 5 { if len(os.Args) < 5 {
// the user is doing autocomplete on the command itself // the user is doing autocomplete on the command itself
newauto.Partial = "" newauto.Partial = ""
@ -180,9 +193,11 @@ func parseArgv(argname string) *Auto {
newauto.Argv = []string{""} newauto.Argv = []string{""}
return newauto return newauto
} }
newauto.Argv = os.Args[4:]
if newauto.Partial == "''" { if newauto.Partial == "''" {
newauto.Partial = "" newauto.Partial = ""
newauto.Cmd = "todo:findme" newauto.Cmd = "todo:findme"
}
// set pb.Cmd to the first thing that doesn't have a '-' arg // set pb.Cmd to the first thing that doesn't have a '-' arg
for _, s := range newauto.Argv { for _, s := range newauto.Argv {
if strings.HasPrefix(s, "-") { if strings.HasPrefix(s, "-") {
@ -191,6 +206,8 @@ func parseArgv(argname string) *Auto {
newauto.Cmd = s newauto.Cmd = s
break break
} }
if newauto.Cmd == "" {
newauto.Cmd = strings.Join(newauto.Argv, "BLAH")
} }
return newauto return newauto
} }