Sort rofi entries by frequency used.

This commit is contained in:
2024-05-29 15:43:59 -05:00
parent c02b8f3dff
commit 365e343a95
3 changed files with 121 additions and 1 deletions

View File

@@ -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())
}
}

View File

@@ -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")