more improvements with autocomplete
This commit is contained in:
parent
b658111125
commit
1522a2fef0
21
bash2.go
21
bash2.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue