summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--history.go53
-rw-r--r--theMagicOfAutocomplete.go43
2 files changed, 41 insertions, 55 deletions
diff --git a/history.go b/history.go
deleted file mode 100644
index f26ba8e..0000000
--- a/history.go
+++ /dev/null
@@ -1,53 +0,0 @@
-package prep
-
-// essentially .bash_history, but in a protobuf and for any shell
-// An elegant weapon... for a more civilized age.
-// stores files ./cache/argv/<appname>.pb
-
-import (
- "time"
-
- "go.wit.com/lib/config"
- durationpb "google.golang.org/protobuf/types/known/durationpb"
-)
-
-func (newpb *Auto) getHistoryPB() (*Autos, error) {
- all := NewAutos()
- err := config.LoadCache(all, "argv", newpb.Argname) // loads ~/.cache/argv/forge.pb
- if err != nil {
- // newpb.History = false
- return all, err
- }
-
- if all.Len() == 0 {
- // first time
- all.Clone(newpb)
- err = all.Save()
- }
-
- var last *Auto
- // find the last entry. this is dumb way to do it
- for found := range all.IterAll() {
- last = found
- }
-
- // set the duration since the last auto complete
- dur := time.Since(last.Ctime.AsTime())
- newpb.Duration = durationpb.New(dur)
-
- // roll the autocomplete file
- if all.Len() > 15 {
- newpb.Debugf("DEBUG: trim() history is over 100 len=%d vs new=%d", all.Len(), all.Len()-90)
- all.Autos = all.Autos[all.Len()-10:]
- // newall.Autos = all.Autos[0:10]
- // for _, found := range all.Autos[0:10] {
- // newall.Append(found)
- // }
- }
-
- all.Clone(newpb)
- err = all.Save()
-
- newpb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err)
- return all, err
-}
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 3202af3..fa392a1 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -4,10 +4,13 @@ package prep
// lots of the fun magic is in here
import (
+ "errors"
"os"
"time"
"go.wit.com/dev/alexflint/arg"
+ "go.wit.com/lib/config"
+ durationpb "google.golang.org/protobuf/types/known/durationpb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
@@ -31,17 +34,53 @@ func Autocomplete(dest any) *Auto {
pb.PrintDebug()
}
- all, err := pb.getHistoryPB() // read in the history protobuf file
+ // all, err := pb.getHistoryPB() // read in the history protobuf file
+ // func (newpb *Auto) getHistoryPB() (*Autos, error) {
+ all := NewAutos()
+ err := config.LoadCache(all, "argv", pb.Argname) // loads ~/.cache/argv/forge.pb
if err != nil {
// there is no history
}
+ if all.Len() == 0 {
+ // first time
+ all.Clone(pb)
+ err = all.Save()
+ }
+
+ // set the duration since the last auto complete
+ // find the last entry. this is dumb way to do it
+ var last *Auto
+ for found := range all.IterAll() {
+ last = found
+ }
+ 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:]
+ // newall.Autos = all.Autos[0:10]
+ // for _, found := range all.Autos[0:10] {
+ // newall.Append(found)
+ // }
+ }
+
+ // save the history
+ all.Clone(pb)
+ errors.Join(err, all.Save())
+
+ pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err)
+ // return all, err
+ //}
+
if pb.Debug {
all.PrintHistory()
}
// turn on debugging if duration < 200 milliseconds
- dur := pb.Duration.AsDuration()
+ dur = pb.Duration.AsDuration()
if dur < time.Millisecond*200 {
pb.Debug = true
pb.Fast = true