@@ -30,9 +30,10 @@ import Data.Maybe (mapMaybe)
3030import Data.Traversable (traverse)
3131
3232import System.Console.Haskeline
33−import System.Directory (doesFileExist, findExecutable)
33+import System.Directory (doesFileExist, findExecutable, getHomeDirectory)
3434import System.Exit
3535import System.Environment.XDG.BaseDir
36+import System.FilePath ((</>), isPathSeparator)
3637import System.Process
3738
3839import qualified Language.PureScript as P
@@ -95,7 +96,7 @@ defaultImports = [P.ProperName "Prelude"]
9596--
9697findNodeProcess :: IO (Maybe String)
9798findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
98− where names = ["nodejs", "node"]
99+ where names = ["nodejs", "node"]
99100
100101-- |
101102-- Grabs the filename where the history is stored.
@@ -115,6 +116,12 @@ getPreludeFilename = Paths.getDataFileName "prelude/prelude.purs"
115116loadModule :: FilePath -> IO (Either String [P.Module])
116117loadModule = fmap (either (Left . show) Right . parseModules) . U.readFile
117118
119+-- |
120+-- Expands tilde in path.
121+--
122+expandTilde :: FilePath -> IO FilePath
123+expandTilde ('~':p:rest) | isPathSeparator p = (</> rest) <$> getHomeDirectory
124+expandTilde p = return p
118125-- Messages
119126
120127-- |
@@ -259,13 +266,14 @@ handleCommand (Expression ls) =
259266handleCommand Help = outputTStrLn helpMessage
260267handleCommand (Import moduleName) = modify (updateImports moduleName)
261268handleCommand (LoadFile filePath) = do
262− exists <- ioToState $ doesFileExist filePath
269+ absPath <- ioToState $ expandTilde filePath
270+ exists <- ioToState $ doesFileExist absPath
263271 if exists then
264− ioToState (loadModule filePath) >>= either outputTStrLn (modify . updateModules)
272+ either outputTStrLn (modify . updateModules) =<< ioToState (loadModule absPath)
265273 else
266274 outputTStrLn $ "Couldn't locate: " ++ filePath
267275handleCommand Reload = do
268− (Right prelude) <- ioToState $ getPreludeFilename >>= loadModule
276+ (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
269277 put (PSCI defaultImports prelude [])
270278handleCommand Unknown = outputTStrLn "Unknown command"
271279