summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go53
1 files changed, 29 insertions, 24 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index e8a63ff..c08df4b 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -27,6 +27,15 @@ func Autocomplete() *Argv {
// initializes the lib/env library
env.Init(me.pb.AppInfo.APPNAME, me.pb.AppInfo.VERSION, cobol.Time(me.pb.AppInfo.BUILDTIME), me.pb.Real, GoodExit, BadExit)
+ // user is trying to setup bash or zsh autocomplete
+ // --bash or --zsh is the first os.Args
+ if me.setupAuto {
+ // --bash or --zsh was passed. try to configure bash-completion
+ MakeAutocompleteFiles(me.pb.AppInfo.APPNAME)
+ // never forget to exit here or you will hate yourself and the choices you have made
+ saveAndExit()
+ }
+
// open the argv cache history file to figure out the timing
examineArgvHistory()
@@ -41,15 +50,6 @@ func Autocomplete() *Argv {
// fmt.Println("no gui init")
}
- // user is trying to setup bash or zsh autocomplete
- // --bash or --zsh is the first os.Args
- if me.setupAuto {
- // --bash or --zsh was passed. try to configure bash-completion
- MakeAutocompleteFiles(me.pb.AppInfo.APPNAME)
- // 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))
for _, a := range me.pb.Real {
if strings.HasPrefix(a, "--") {
@@ -83,7 +83,7 @@ func Autocomplete() *Argv {
func prepareStdout() {
if me.debug {
// add an initial debug line
- me.pb.PrintDebug(me.last.GetCmd())
+ me.pb.printDebug(me.last.GetCmd())
}
if strings.HasPrefix(me.pb.Partial, "'--argv") {
@@ -98,11 +98,11 @@ func prepareStdout() {
lastarg := me.pb.Real[len(me.pb.Real)-1]
// this is a work in progress
if lastarg == "--gui" {
- me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real)
+ me.pb.debugf("DEBUG: real=(%v) found --gui", me.pb.Real)
PB.Stdout += " andlabs gogui"
return
} else {
- // me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val)
+ // me.pb.debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val)
}
}
@@ -127,14 +127,14 @@ func savePB() {
func saveAndExit() {
if me.debug {
- me.all.PrintHistory("HIST")
+ me.all.printHistory("HIST")
fmt.Fprintf(Stddbg, "me.debug=true pb.Stdout=(%v)\n", strings.TrimSpace(PB.Stdout))
- PrintStddbg()
+ printStddbg()
}
PB.ErrCounter += 1
if PB.ErrCounter < 3 {
- PrintStderr()
+ printStderr()
} else {
if PB.ErrCounter > 10 {
PB.ErrCounter = 0
@@ -142,7 +142,7 @@ func saveAndExit() {
}
PB.OutCounter += 1
- PrintStdout()
+ printStdout()
if PB.OutCounter < 3 {
} else {
if PB.OutCounter > 5 {
@@ -172,20 +172,21 @@ func examineArgvHistory() {
me.debug = true
me.pb.Stddbg += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err)
me.pb.Stddbg += fmt.Sprintf("argvpb.Load() history file failed")
- PrintStderr()
+ printStderr()
+ printStddbg()
me.all = NewArgvs()
me.debug = true
return
}
if me.debug {
// use this if you are having trouble debugging this code
- // me.all.PrintHistory("EARLY")
+ // me.all.printHistory("EARLY")
}
// roll the autocomplete file
maxsize := 17
trim := 10
if me.all.Len() > maxsize {
- me.pb.Debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim)
+ me.pb.debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim)
me.all.Argvs = me.all.Argvs[me.all.Len()-trim:]
// newall.Autos = me.all.Autos[0:10]
}
@@ -216,19 +217,23 @@ func examineArgvHistory() {
// more early code for debugging if things go really wrong
// if me.debug {
// hist := fmt.Sprintf("HISTNIL(%d)", counter)
- // pb.PrintDebugNew(hist, "too soon")
+ // pb.printDebugNew(hist, "too soon")
// }
}
- // only have nil values in the .pb file. just die for now
+ // only have nil values in the .pb file. todo: figure out why this happens
if me.all.Len() == 0 {
me.debug = true
fmt.Fprintf(Stddbg, "examineArgvHistory() empty file %s\n", me.all.Filename)
- saveAndExit()
+ // saveAndExit()
}
- // finally safe to get the last history entry
- me.last = me.all.Argvs[me.all.Len()-1]
+ // get the last autocomplete
+ if me.all.Len() == 0 {
+ me.last = new(Argv)
+ } else {
+ me.last = me.all.Argvs[me.all.Len()-1]
+ }
// compute the duration since the last time
dur := time.Since(me.last.Ctime.AsTime())