environment :: [Proc] -> [FilePath] -> IO Env
environment ps fs = do
    es  <- filterM doesFileExist $ getEnvFiles ps
    env <- mapM read' $ es ++ fs
    return $! merge (parse env) ps
  where
    read' path = logDebug ("Reading " ++ path ++ " ...") >> Text.readFile path

    merge env = nubBy ((==) `on` fst)
        . (++ env)
        . getRemoteEnv

    parse = map (second Text.tail . Text.break (== '='))
        . Text.lines
        . Text.concat
environment :: [Proc] -> [FilePath] -> IO Env
environment ps fs = do
    es  <- filterM doesFileExist $ getEnvFiles ps
    env <- mapM read' $ es ++ fs
    return $! merge (parse env) ps
  where
    read' path = logDebug ("Reading " ++ path ++ " ...") >> Text.readFile path

    merge env = nubBy ((==) `on` fst)
        . (++ env)
        . getRemoteEnv

    parse = map (second Text.tail . Text.break (== '='))
        . Text.lines
        . Text.concat
environment ps fs = do
    es  <- filterM doesFileExist $ getEnvFiles ps
    env <- mapM read' $ es ++ fs
    return $! merge (parse env) ps
  where
    read' path = logDebug ("Reading " ++ path ++ " ...") >> Text.readFile path

    merge env = nubBy ((==) `on` fst)
        . (++ env)
        . getRemoteEnv

    parse = map (second Text.tail . Text.break (== '='))
        . Text.lines
        . Text.concat