summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 05:41:49 -0500
committerJeff Carr <[email protected]>2025-10-12 05:41:49 -0500
commitbea3d53daa187b72919571e5b0f0cbb18baf1f11 (patch)
tree516f5151cd5f77683eded1d0c7d655c550727f06
parenta4e6b6bf814335ba972a975317381c9585015d5b (diff)
keep house cleaning
-rw-r--r--history.go36
-rw-r--r--makeAutocompleteFiles.bash.go2
-rw-r--r--makeAutocompleteFiles.go6
-rw-r--r--makeAutocompleteFiles.zsh.go2
-rw-r--r--theMagicOfAutocomplete.go13
5 files changed, 33 insertions, 26 deletions
diff --git a/history.go b/history.go
index a2956df..74dc823 100644
--- a/history.go
+++ b/history.go
@@ -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)
}