@@ -91,12 +91,15 @@ supportModule =
9191
9292-- File helpers
9393
94+onFirstFileMatching :: Monad m => (b -> m (Maybe a)) -> [b] -> m (Maybe a)
95+onFirstFileMatching f pathVariants = runMaybeT . msum $ map (MaybeT . f) pathVariants
96+
9497-- |
9598-- Locates the node executable.
9699-- Checks for either @nodejs@ or @node@.
97100--
98101findNodeProcess :: IO (Maybe String)
99−findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
102+findNodeProcess = onFirstFileMatching findExecutable names
100103 where names = ["nodejs", "node"]
101104
102105-- |
@@ -486,18 +489,27 @@ whenFileExists filePath f = do
486489 then f absPath
487490 else PSCI . outputStrLn $ "Couldn't locate: " ++ filePath
488491
492+-- |
493+-- Attempts to read initial commands from '.psci' in the present working
494+-- directory then the user's home
495+--
489496loadUserConfig :: IO (Maybe [Command])
490−loadUserConfig = do
491− configFile <- (</> ".psci") <$> getCurrentDirectory
492− exists <- doesFileExist configFile
493− if exists
494− then do
495− ls <- lines <$> readFile configFile
496− case mapM parseCommand ls of
497− Left err -> print err >> exitFailure
498− Right cs -> return $ Just cs
499− else
500− return Nothing
497+loadUserConfig = onFirstFileMatching readCommands pathGetters
498+ where
499+ pathGetters = [getCurrentDirectory, getHomeDirectory]
500+ readCommands :: IO FilePath -> IO (Maybe [Command])
501+ readCommands path = do
502+ configFile <- (</> ".psci") <$> path
503+ exists <- doesFileExist configFile
504+ if exists
505+ then do
506+ ls <- lines <$> readFile configFile
507+ case mapM parseCommand ls of
508+ Left err -> print err >> exitFailure
509+ Right cs -> return $ Just cs
510+ else
511+ return Nothing
512+
501513
502514-- | Checks if the Console module is defined
503515consoleIsDefined :: [P.Module] -> Bool