Fix pass
This commit is contained in:
parent
e206492ae9
commit
1d3c55f3e9
1 changed files with 14 additions and 10 deletions
|
@ -40,17 +40,8 @@ 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
|
||||
passwords <- sort <$> liftIO getPasswords
|
||||
-- Other change, use infixof instead of prefixof
|
||||
mkXPrompt (Pass label) conf
|
||||
(\input -> pure (sortBy (compare `on` levenshtein input)
|
||||
. take 5
|
||||
. filter (consumes input)
|
||||
$ passwords)) f
|
||||
mkXPrompt (Pass label) conf (passComplFun passwords) f
|
||||
where
|
||||
consumes [] _ = True -- everything consumed
|
||||
consumes (_:_) [] = False -- all not consumed
|
||||
consumes (a:xs) (a':ys) | a == a' = consumes xs ys
|
||||
| otherwise = consumes (a:xs) ys
|
||||
getPasswords = do
|
||||
passwordStoreDir <- (</> "pass") <$> getHomeDirectory
|
||||
files <- runProcessWithInput "find"
|
||||
|
@ -58,6 +49,19 @@ mkPassPrompt label f conf = do
|
|||
, "%p\n"] []
|
||||
return . lines $ files
|
||||
|
||||
-- | Find all entries (`allPasses`) matching `input`
|
||||
passComplFun :: [String] -> String -> IO [String]
|
||||
passComplFun allPasses input = pure $
|
||||
sortBy (compare `on` levenshtein input)
|
||||
. take 5
|
||||
. filter (consumes input)
|
||||
$ allPasses
|
||||
where
|
||||
consumes [] _ = True -- everything consumed
|
||||
consumes (_:_) [] = False -- all not consumed
|
||||
consumes (a:xs) (a':ys) | a == a' = consumes xs ys
|
||||
| otherwise = consumes (a:xs) ys
|
||||
|
||||
selectPassword :: String -> X ()
|
||||
selectPassword pass = spawn $ "gpg --decrypt " ++ pass ++ " | copy"
|
||||
-- “copy” comes with the xmonad module in the nix configuration
|
||||
|
|
Loading…
Reference in a new issue