diff options
Diffstat (limited to 'complete.go')
| -rw-r--r-- | complete.go | 85 |
1 files changed, 55 insertions, 30 deletions
diff --git a/complete.go b/complete.go index dee60c5..235e73d 100644 --- a/complete.go +++ b/complete.go @@ -82,7 +82,9 @@ func (pb *Auto) doHandlePB() error { dur := time.Since(found.Ctime.AsTime()) pb.Duration = durationpb.New(dur) // found.PrintDebug() - pb.Debugf("AUTO HISTORY: age=%s cmd='%s' partial='%s' argv='%v'", shell.FormatDuration(dur), found.Cmd, found.Partial, found.Argv) + cmd := fmt.Sprintf("cmd='%s'", found.Cmd) + arglast := fmt.Sprintf("last='%s'", found.Last) + pb.Debugf("AUTO HISTORY: age=%-6.6s %-18.18s %-18.18s partial='%s' argv='%v'", shell.FormatDuration(dur), cmd, arglast, found.Partial, found.Argv) last = found } } @@ -208,60 +210,71 @@ func (pb *Auto) Autocomplete2(sendthis string) { } func parseArgv(argname string) *Auto { - newauto := new(Auto) - newauto.Argname = argname + pb := new(Auto) + pb.Argname = argname if len(os.Args) == 0 { - return newauto + return pb } if len(os.Args) > 1 && os.Args[1] == "--bash" { - newauto.SetupAuto = true - return newauto + pb.SetupAuto = true + return pb } // HACK: set debug flag if --autodebug is passed for _, s := range os.Args { if s == "--autodebug" { - newauto.Debug = true + pb.Debug = true } } // should we do auto complete here? if len(os.Args) > 1 && os.Args[1] == "--auto-complete" { - newauto.IsAuto = true - newauto.Arg0 = os.Args[0] - newauto.Arg1 = os.Args[1] - newauto.Partial = os.Args[2] - newauto.Arg3 = os.Args[3] + pb.IsAuto = true + pb.Arg0 = os.Args[0] + pb.Arg1 = os.Args[1] + pb.Partial = os.Args[2] + pb.Arg3 = os.Args[3] if len(os.Args) < 5 { // the user is doing autocomplete on the command itself - newauto.Partial = "" - newauto.Cmd = "" - newauto.Argv = []string{""} - return newauto + pb.Partial = "" + pb.Cmd = "" + pb.Argv = []string{""} + return pb } - newauto.Argv = os.Args[4:] - if newauto.Partial == "''" { - newauto.Partial = "" - newauto.Cmd = "todo:findme" + pb.Argv = os.Args[4:] + if pb.Partial == "''" { + pb.Partial = "" + pb.Cmd = "todo:findme" } // set pb.Cmd to the first thing that doesn't have a '-' arg - for _, s := range newauto.Argv { + for _, s := range pb.Argv { if strings.HasPrefix(s, "-") { continue } - newauto.Cmd = s + pb.Cmd = s break } - if newauto.Partial == "'"+newauto.Cmd+"'" { + if pb.Partial == "'"+pb.Cmd+"'" { // not really a command, it's just a partially inputed string from the user - newauto.Cmd = "" + pb.Cmd = "" } - // if newauto.Cmd == "" { - // newauto.Cmd = strings.Join(newauto.Argv, "BLAH") + // try to figure out what the last argv is + for _, s := range pb.Argv { + p := fmt.Sprintf("'%s'", s) + if pb.Partial == p { + pb.Debugf("DEBUG: MATCH Partial %s %s", s, p) + continue + } else { + pb.Debugf("DEBUG: NO MATCH Partial %s %s", s, p) + } + pb.Last = s + } + // if pb.Cmd == "" { + // pb.Cmd = strings.Join(pb.Argv, "BLAH") // } } - return newauto + return pb } // also try to parse/send cur (?) @@ -301,9 +314,7 @@ func Bash2(argname string, appAutoFunc func(*Auto)) *Auto { // func Bash3(appAutoFunc func(*Auto), dest any) *Auto { func Bash3(dest any) *Auto { myAuto = new(AutoArgs) - // myAuto.appName = argname - // myAuto.autoFunc = appAutoFunc - newTest(dest) + findAppInfo(dest) // parses back to main() for argv info pb := parseArgv(myAuto.appName) if pb.SetupAuto { @@ -312,6 +323,9 @@ func Bash3(dest any) *Auto { os.Exit(0) } + myAuto.match = make(map[string]string) + myAuto.match["--gui"] = "andlabs gocui" + if pb.Debug { // dump debug info pb.PrintDebug() @@ -325,6 +339,8 @@ func Bash3(dest any) *Auto { pb.Debug = true } + // prepart["--gui"] = "andlabs gocui" + arg.Register(&argBash) flags := []string{} for _, s := range pb.Argv { @@ -348,6 +364,15 @@ func Bash3(dest any) *Auto { } if pb.IsAuto { + for key, val := range myAuto.match { + if pb.Last == key { + pb.Debugf("DEBUG: last=%s found key %s = %s", pb.Last, key, val) + pb.Autocomplete2(val) + os.Exit(0) + } else { + pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val) + } + } myAuto.autoFunc(pb) // run the autocomplete function the user made for their application if pb.Debug { // TODO: |
