diff options
| author | Jeff Carr <[email protected]> | 2025-10-12 02:11:40 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-12 02:11:40 -0500 |
| commit | 0c84559372b1d4c293ac10aa2b6de6e53ebb1163 (patch) | |
| tree | 14c92db2cbe6544c0c6b742e006d4736fe8da1d7 /theMagicOfAutocomplete.go | |
| parent | bf9f85a721d6045e631df9abe91f02d9723fcd19 (diff) | |
more housecleaning
Diffstat (limited to 'theMagicOfAutocomplete.go')
| -rw-r--r-- | theMagicOfAutocomplete.go | 74 |
1 files changed, 20 insertions, 54 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 9de2d7f..e4407a3 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -4,14 +4,10 @@ package prep // lots of the fun magic is in here import ( - "fmt" "os" - "path/filepath" "time" "go.wit.com/dev/alexflint/arg" - "go.wit.com/lib/config" - "go.wit.com/log" ) func Autocomplete(dest any) *Auto { @@ -38,8 +34,6 @@ func Autocomplete(dest any) *Auto { pb.Debug = true } - // prepart["--gui"] = "andlabs gocui" - arg.Register(&argBash) flags := []string{} for _, s := range pb.Argv { @@ -62,60 +56,32 @@ func Autocomplete(dest any) *Auto { // pb.Debugf("DEBUG: myAuto.pp is ok after ParseFlags()") } - if pb.IsAuto { - // myAuto.match = make(map[string]string) - // myAuto.match["--gui"] = "andlabs gocui" - // for key, val := range myAuto.match { - if pb.Last == "--gui" { - pb.Debugf("DEBUG: last=%s found --gui", pb.Last) - pb.Autocomplete2("andlabs gogui") - os.Exit(0) - } else { - // pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val) - } - // } - if myAuto.autoFunc == nil { - pb.SubCommand(pb.Argv...) - } else { - myAuto.autoFunc(pb) // run the autocomplete function the user made for their application - } - if pb.Debug { - // TODO: - // check here to see if there was any completion text sent - // if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user - } - os.Exit(0) + // not autocompleting. just return to the application + if !pb.IsAuto { + arg.Register(&argBash) + myAuto.pp = arg.MustParse(dest) + return pb } - arg.Register(&argBash) - myAuto.pp = arg.MustParse(dest) - return pb -} - -// makes a autocomplete file for your command -func makeAutocompleteFiles(argname string) { - fmt.Println(makeBashCompletionText2(argname)) - - homeDir, err := os.UserHomeDir() - if err != nil { - log.Printf("# %v\n", err) + // this is a work in progress + if pb.Last == "--gui" { + pb.Debugf("DEBUG: last=%s found --gui", pb.Last) + pb.Autocomplete2("andlabs gogui") os.Exit(0) - } - filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname) - if config.Exists(filename) { - log.Fprintln(os.Stderr, "# file already exists", filename) - // os.Exit(0) - } - basedir, _ := filepath.Split(filename) - if !config.IsDir(basedir) { - os.MkdirAll(basedir, os.ModePerm) + } else { + // pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val) } - if f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil { - f.Write([]byte(makeBashCompletionText2(argname))) - f.Close() + if myAuto.autoFunc == nil { + pb.SubCommand(pb.Argv...) } else { - log.Fprintln(os.Stderr, "# open file error", filename, err) + myAuto.autoFunc(pb) // run the autocomplete function the user made for their application + } + if pb.Debug { + // TODO: + // check here to see if there was any completion text sent + // if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user } os.Exit(0) + return nil } |
