Sort rofi entries by frequency used.
This commit is contained in:
21
cmd/rofi.go
21
cmd/rofi.go
@@ -6,6 +6,7 @@ package cmd
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"git.bullercodeworks.com/brian/keepass-cli/models"
|
||||
@@ -55,15 +56,33 @@ func runRofi(cmd *cobra.Command, args []string) error {
|
||||
path = append(path, strings.Split(args[i], "/")...)
|
||||
}
|
||||
|
||||
var freqs *models.Frequencies
|
||||
if len(path) == 0 || argIsPw {
|
||||
list := db.GetAllEntriesFromRoot()
|
||||
var printList []string
|
||||
for i := range list {
|
||||
fmt.Println(strings.Join(list[i], "/"))
|
||||
printList = append(printList, strings.Join(list[i], "/"))
|
||||
}
|
||||
|
||||
freqs, err = models.LoadFrequencies()
|
||||
if err == nil {
|
||||
sort.Slice(printList, func(i, j int) bool {
|
||||
return freqs.GetTimes(printList[i]) > freqs.GetTimes(printList[j])
|
||||
})
|
||||
}
|
||||
for i := range printList {
|
||||
fmt.Println(printList[i])
|
||||
}
|
||||
} else {
|
||||
if entry, entryErr := db.FindEntryFromRoot(path); entryErr != nil {
|
||||
return entryErr
|
||||
} else {
|
||||
freqPath := strings.Join(path, "/")
|
||||
freqs, err = models.LoadFrequencies()
|
||||
if err == nil {
|
||||
freqs.IncrementEntry(freqPath)
|
||||
freqs.Save()
|
||||
}
|
||||
return util.WriteToClipboard(entry.GetPassword())
|
||||
}
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ Copyright © 2024 Brian Buller <brian@bullercodeworks.com>
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"git.bullercodeworks.com/brian/keepass-cli/models"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -19,6 +20,7 @@ func init() {
|
||||
}
|
||||
|
||||
func runTestCmd(cmd *cobra.Command, args []string) error {
|
||||
models.LoadFrequencies()
|
||||
/*
|
||||
var db *models.KeePassDB
|
||||
pass, err := util.PromptUserForPassword("Master Password")
|
||||
|
Reference in New Issue
Block a user