summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-17 22:36:20 -0500
committerJeff Carr <[email protected]>2025-09-17 22:36:20 -0500
commit1522a2fef0ed356f12a5c9cc011cdad6b4cd4a05 (patch)
treecbcf24d5694dee64b015dee5afc412f9ed8d53d8
parentb658111125c23efe72263f5f4358b7ffd6fb58ce (diff)
more improvements with autocomplete
-rw-r--r--bash2.go35
1 files changed, 26 insertions, 9 deletions
diff --git a/bash2.go b/bash2.go
index 1526d92..e636ee1 100644
--- a/bash2.go
+++ b/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
}