diff options
| -rw-r--r-- | history.go | 36 | ||||
| -rw-r--r-- | makeAutocompleteFiles.bash.go | 2 | ||||
| -rw-r--r-- | makeAutocompleteFiles.go | 6 | ||||
| -rw-r--r-- | makeAutocompleteFiles.zsh.go | 2 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 13 |
5 files changed, 33 insertions, 26 deletions
@@ -11,28 +11,33 @@ import ( "go.wit.com/lib/cobol" "go.wit.com/lib/config" durationpb "google.golang.org/protobuf/types/known/durationpb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) func (pb *Auto) getHistoryPB() error { all := NewAutos() err := config.LoadCache(all, "argv", pb.Argname) // loads ~/.cache/argv/forge.pb + if err != nil { + // pb.History = false + return err + } var last *Auto - if err == nil { - for found := range all.IterAll() { - dur := time.Since(found.Ctime.AsTime()) - pb.Duration = durationpb.New(dur) - // found.PrintDebug() - cmd := fmt.Sprintf("cmd='%s'", found.Cmd) - arglast := fmt.Sprintf("last='%s'", found.Last) - partial := fmt.Sprintf("p='%s'", found.Partial) - age := fmt.Sprintf("age='%-6.6s'", cobol.FormatDuration(dur)) - pb.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) - last = found - } + // find the last entry & print out debugging history + for found := range all.IterAll() { + cmd := fmt.Sprintf("cmd='%s'", found.Cmd) + arglast := fmt.Sprintf("last='%s'", found.Last) + partial := fmt.Sprintf("p='%s'", found.Partial) + dur := time.Since(found.Ctime.AsTime()) + age := fmt.Sprintf("age=(%s)", cobol.FormatDuration(dur)) + pb.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) + last = found } + // set the duration since the last auto complete + dur := time.Since(last.Ctime.AsTime()) + pb.Duration = durationpb.New(dur) + + // roll the autocomplete file if all.Len() > 15 { pb.Debugf("DEBUG: trim() history is over 100 len=%d vs new=%d", all.Len(), all.Len()-90) all.Autos = all.Autos[all.Len()-10:] @@ -47,10 +52,7 @@ func (pb *Auto) getHistoryPB() error { last = new(Auto) } - // this is the start time of the binary - now := time.Now() - pb.Ctime = timestamppb.New(now) - all.Append(pb) + all.Clone(pb) err = all.Save() pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) diff --git a/makeAutocompleteFiles.bash.go b/makeAutocompleteFiles.bash.go index d27f167..d66bf90 100644 --- a/makeAutocompleteFiles.bash.go +++ b/makeAutocompleteFiles.bash.go @@ -13,7 +13,7 @@ import ( "go.wit.com/log" ) -func makeBashCompleteFiles(argname string) { +func MakeBashCompleteFiles(argname string) { fmt.Println(makeBashCompletionText2(argname)) homeDir, err := os.UserHomeDir() diff --git a/makeAutocompleteFiles.go b/makeAutocompleteFiles.go index 2d19114..2010c42 100644 --- a/makeAutocompleteFiles.go +++ b/makeAutocompleteFiles.go @@ -4,12 +4,12 @@ import ( "os" ) -func makeAutocompleteFiles(argname string) { +func MakeAutocompleteFiles(argname string) { if _, ok := os.LookupEnv("BASH_VERSION"); ok { - makeBashCompleteFiles(argname) + MakeBashCompleteFiles(argname) } if _, ok := os.LookupEnv("ZSH_VERSION"); ok { - makeZshCompleteFiles(argname) + MakeZshCompleteFiles(argname) } } diff --git a/makeAutocompleteFiles.zsh.go b/makeAutocompleteFiles.zsh.go index ca8f4be..7b4a3f0 100644 --- a/makeAutocompleteFiles.zsh.go +++ b/makeAutocompleteFiles.zsh.go @@ -4,7 +4,7 @@ import "go.wit.com/log" // makes the autocomplete files for 'zsh' -func makeZshCompleteFiles(argname string) { +func MakeZshCompleteFiles(argname string) { log.Info("todo: zsh") } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index e6c4daf..d28dd8b 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -8,16 +8,21 @@ import ( "time" "go.wit.com/dev/alexflint/arg" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) func Autocomplete(dest any) *Auto { - myAuto = new(AutoArgs) - findAppInfo(dest) // parses back to main() for argv info - + myAuto = new(AutoArgs) // todo: redo this + findAppInfo(dest) // parses back to main() for argv info pb := parseArgv(myAuto.appName) // parses os.Args into a protobuf + + // set the start time of the binary + now := time.Now() + pb.Ctime = timestamppb.New(now) + if pb.SetupAuto { // --bash was passed. try to configure bash-completion - makeAutocompleteFiles(myAuto.appName) + MakeAutocompleteFiles(myAuto.appName) os.Exit(0) } |
