From c994eb6e375d47c6ad065ded4ec66936a3047043 Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Wed, 18 Feb 2015 10:18:16 +0100 Subject: XMonad.Prompt.Pass: Handle hierachical password stores Ignore-this: 2f0a02613780067d324b04a8cdb9c0ed pass stores its passwords in directories, so the contents of the directory store needs to be enumerated recursively. Alexander Sulfrian provided this patch on the mailinglist, which I tested (it works) and cleaned up slightly. darcs-hash:20150218091816-23c07-6951b0fd1dea96873ec7f7968e5775db8f4520be.gz --- XMonad/Prompt/Pass.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'XMonad/Prompt/Pass.hs') diff --git a/XMonad/Prompt/Pass.hs b/XMonad/Prompt/Pass.hs index db4ce2d..099a1a6 100644 --- a/XMonad/Prompt/Pass.hs +++ b/XMonad/Prompt/Pass.hs @@ -50,8 +50,9 @@ import XMonad.Prompt ( XPrompt , mkXPrompt , mkComplFunFromList) import System.Directory (getDirectoryContents, getHomeDirectory) -import System.FilePath (takeBaseName, combine) +import System.FilePath (takeBaseName, takeExtension, dropExtension, combine) import System.Posix.Env (getEnv) +import XMonad.Util.Run (runProcessWithInput) -- $usages -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: @@ -137,6 +138,14 @@ removePassword :: String -> X () removePassword passLabel = spawn $ "pass rm --force " ++ passLabel -- | Retrieve the list of passwords from the password storage 'passwordStoreDir --- -getPasswords :: String -> IO [String] -getPasswords passwordStoreDir = liftM (map takeBaseName) $ getDirectoryContents passwordStoreDir +getPasswords passwordStoreDir = do + files <- runProcessWithInput "find" [ + passwordStoreDir, + "-type", "f", + "-name", "*.gpg", + "-printf", "%P\n"] [] + return $ map removeGpgExtension $ lines files + +removeGpgExtension :: String -> String +removeGpgExtension file | takeExtension file == ".gpg" = dropExtension file + | otherwise = file -- cgit v1.2.3