Skip to content
Permalink
Browse files

Add search command

  • Loading branch information...
Raggaer committed Feb 21, 2019
1 parent 6aae586 commit 452612fe385633eebc8c662ae515e36672eaff77
Showing with 23 additions and 0 deletions.
  1. +10 −0 command.go
  2. +13 −0 entry.go
@@ -88,6 +88,16 @@ var commands = []command{
Help: "Removes an entry of the current group (rm <entry path|number>)",
HelpSmall: "Removes an entry of the current group (rm <entry path|number>)",
},
{
Key: "search",
Fn: func(args []string) {
if len(args) >= 1 {
search(args)
}
},
Help: "Performs a fuzzy search on all the current group entries",
HelpSmall: "Performs a fuzzy search on all the current group entries",
},
}

func handleUserInput(input string) {
@@ -6,6 +6,7 @@ import (
"strings"

"github.com/atotto/clipboard"
"github.com/lithammer/fuzzysearch/fuzzy"
"github.com/sethvargo/go-password/password"
"github.com/tobischo/gokeepasslib/v2"
)
@@ -48,6 +49,18 @@ func deleteEntry(entry *gokeepasslib.Entry) bool {
return false
}

// Command "search" searches for entries of the current group
func search(args []string) {
// We combine args again to allow spaces
search := strings.ToLower(strings.Join(args, " "))
for i, entry := range currentGroup().Entries {
if !fuzzy.Match(search, strings.ToLower(entry.GetTitle())) {
continue
}
fmt.Printf("%d. %s\r\n", i+1, entry.GetTitle())
}
}

// Command "show" shows information about an entry
func show(args []string) {
entry := getEntryByNameOrId(args[0])

0 comments on commit 452612f

Please sign in to comment.
You can’t perform that action at this time.