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