summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go40
1 files changed, 26 insertions, 14 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 571c280..9c9010b 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -79,10 +79,11 @@ func Autocomplete(dest any) *Argv {
// user is trying to setup bash or zsh autocomplete
// --bash or --zsh is the first os.Args
if me.setupAuto {
+ savePB()
// --bash or --zsh was passed. try to configure bash-completion
MakeAutocompleteFiles(me.pb.AppInfo.APPNAME)
- // never forget to run this our you will hate yourself and the choices you have made
- os.Exit(0)
+ // never forget to exit here or you will hate yourself and the choices you have made
+ saveAndExit()
}
env.SetGlobal("argv", "real", fmt.Sprintf("%v", me.pb.Real))
@@ -94,8 +95,10 @@ func Autocomplete(dest any) *Argv {
if me.isAuto {
// do autocomplete and exit
+ savePB()
doAutocomplete()
- os.Exit(0)
+ // todo: this never gets here. fix that
+ saveAndExit()
}
// not autocompleting. return to the application
@@ -126,6 +129,7 @@ func doAutocomplete() {
// dump debug info
me.pb.PrintDebug()
me.all.PrintHistory()
+ // me.pb.PrintStderr()
}
// roll the autocomplete file
@@ -182,7 +186,7 @@ func doAutocomplete() {
me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real)
me.pb.PrintStderr()
me.pb.SendString("andlabs gogui")
- os.Exit(0)
+ saveAndExit()
} else {
// me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", me.last, key, val)
}
@@ -219,6 +223,8 @@ func doAutocomplete() {
me.pb.HelpCounter = me.last.HelpCounter + 1
if me.pb.HelpCounter < 3 {
me.pb.PrintStderr()
+ } else {
+ saveAndExit()
}
} else {
// this means the user is pressing tab. no longer doing stderr
@@ -232,21 +238,27 @@ func doAutocomplete() {
me.pb.HelpCounter = 0
}
} else {
+ if me.autoFunc == nil {
+ me.pb.SubCommand(me.pb.Real...)
+ } else {
+ me.autoFunc(me.pb) // run the autocomplete function the user made for their application
+ }
+ if me.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
+ }
}
+ saveAndExit()
+}
+func savePB() {
// save now. this is near the end probably
me.all.Clone(me.pb)
errors.Join(me.Err, me.all.Save())
+}
- if me.autoFunc == nil {
- me.pb.SubCommand(me.pb.Real...)
- } else {
- me.autoFunc(me.pb) // run the autocomplete function the user made for their application
- }
- if me.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
- }
+func saveAndExit() {
+ savePB()
os.Exit(0)
}