    {-# LANGUAGE OverloadedStrings #-}
    module System.Taffybar.Auth where

    import           Control.Arrow
    import           Control.Monad.IO.Class
    import           Data.Maybe
    import           System.Taffybar.Util
    import           Text.Regex

    fieldRegex :: Regex
    fieldRegex :: Regex
    fieldRegex = String -> Bool -> Bool -> Regex
    mkRegexWithOpts "^(.*?): *(.*?)$" Bool
    True Bool
    True

    passGet :: MonadIO m => String -> m (Either String (String, [(String, String)]))
    passGet :: String -> m (Either String (String, [(String, String)]))
    passGet credentialName :: String
    credentialName =
      (String -> (String, [(String, String)]))
    -> Either String String
    -> Either String (String, [(String, String)])
    forall (a :: * -> * -> *) b c d.
    ArrowChoice a =>
    a b c -> a (Either d b) (Either d c)
    right ([String] -> (String, [(String, String)])
    getPassComponents ([String] -> (String, [(String, String)]))
    -> (String -> [String]) -> String -> (String, [(String, String)])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . String -> [String]
    lines) (Either String String
     -> Either String (String, [(String, String)]))
    -> m (Either String String)
    -> m (Either String (String, [(String, String)]))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$>
            [String] -> m (Either String String)
    forall (m :: * -> *).
    MonadIO m =>
    [String] -> m (Either String String)
    runCommandFromPath ["pass", "show", String
    credentialName]
      where getPassComponents :: [String] -> (String, [(String, String)])
    getPassComponents passLines :: [String]
    passLines =
              let entries :: [(String, String)]
    entries =
                    ([String] -> (String, String)) -> [[String]] -> [(String, String)]
    forall a b. (a -> b) -> [a] -> [b]
    map [String] -> (String, String)
    forall b. IsString b => [b] -> (b, b)
    buildEntry ([[String]] -> [(String, String)])
    -> [[String]] -> [(String, String)]
    forall a b. (a -> b) -> a -> b
    $ [Maybe [String]] -> [[String]]
    forall a. [Maybe a] -> [a]
    catMaybes ([Maybe [String]] -> [[String]]) -> [Maybe [String]] -> [[String]]
    forall a b. (a -> b) -> a -> b
    $
                        Regex -> String -> Maybe [String]
    matchRegex Regex
    fieldRegex (String -> Maybe [String]) -> [String] -> [Maybe [String]]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> [String] -> [String]
    forall a. [a] -> [a]
    tail [String]
    passLines
                  buildEntry :: [b] -> (b, b)
    buildEntry [fieldName :: b
    fieldName, fieldValue :: b
    fieldValue] = (b
    fieldName, b
    fieldValue)
                  buildEntry _ = ("", "")
              in ([String] -> String
    forall a. [a] -> a
    head [String]
    passLines, [(String, String)]
    entries)