Shorten the list of return passes shown when searching
This commit is contained in:
parent
b6b5e0d467
commit
2cf1863ef3
1 changed files with 13 additions and 6 deletions
|
@ -37,10 +37,15 @@ passPrompt = mkPassPrompt "Select password" selectPassword
|
|||
|
||||
mkPassPrompt :: String -> (String -> X ()) -> XPConfig -> X ()
|
||||
mkPassPrompt label f conf = do
|
||||
-- I'm just sorting here, but could use some kind of fuzzy matching instead, but it requires a bit more effort
|
||||
-- I'm just sorting here, but could use some kind of fuzzy matching instead,
|
||||
-- but it requires a bit more effort
|
||||
passwords <- sort <$> liftIO getPasswords
|
||||
-- Other change, use infixof instead of prefixof
|
||||
mkXPrompt (Pass label) conf (\input -> pure (sortBy (compare `on` levenshtein input) . filter (consumes input) $ passwords)) f
|
||||
mkXPrompt (Pass label) conf
|
||||
(\input -> pure (sortBy (compare `on` levenshtein input)
|
||||
. take 5
|
||||
. filter (consumes input)
|
||||
$ passwords)) f
|
||||
where
|
||||
consumes [] _ = True -- everything consumed
|
||||
consumes (_:_) [] = False -- all not consumed
|
||||
|
@ -48,7 +53,9 @@ mkPassPrompt label f conf = do
|
|||
| otherwise = consumes (a:xs) ys
|
||||
getPasswords = do
|
||||
passwordStoreDir <- (</> "pass") <$> getHomeDirectory
|
||||
files <- runProcessWithInput "find" [ passwordStoreDir, "-type", "f", "-name", "*.gpg", "-printf", "%p\n"] []
|
||||
files <- runProcessWithInput "find"
|
||||
[ passwordStoreDir, "-type", "f", "-name", "*.gpg", "-printf"
|
||||
, "%p\n"] []
|
||||
return . lines $ files
|
||||
|
||||
selectPassword :: String -> X ()
|
||||
|
|
Loading…
Reference in a new issue