@@ -30,9 +30,10 @@ import Data.Maybe (mapMaybe)
30import Data.Traversable (traverse)
30import Data.Traversable (traverse)
32import System.Console.Haskeline
32import System.Console.Haskeline
33−import System.Directory (doesFileExist, findExecutable)
33+import System.Directory (doesFileExist, findExecutable, getHomeDirectory)
34import System.Exit
34import System.Exit
35import System.Environment.XDG.BaseDir
35import System.Environment.XDG.BaseDir
36+import System.FilePath ((</>), isPathSeparator)
36import System.Process
37import System.Process
38import qualified Language.PureScript as P
39import qualified Language.PureScript as P
@@ -95,7 +96,7 @@ defaultImports = [P.ProperName "Prelude"]
96findNodeProcess :: IO (Maybe String)
97findNodeProcess :: IO (Maybe String)
97findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
98findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
98− where names = ["nodejs", "node"]
99+ where names = ["nodejs", "node"]
101-- Grabs the filename where the history is stored.
102-- Grabs the filename where the history is stored.
@@ -115,6 +116,12 @@ getPreludeFilename = Paths.getDataFileName "prelude/prelude.purs"
115loadModule :: FilePath -> IO (Either String [P.Module])
116loadModule :: FilePath -> IO (Either String [P.Module])
116loadModule = fmap (either (Left . show) Right . parseModules) . U.readFile
117loadModule = fmap (either (Left . show) Right . parseModules) . U.readFile
120+-- Expands tilde in path.
122+expandTilde :: FilePath -> IO FilePath
123+expandTilde ('~':p:rest) | isPathSeparator p = (</> rest) <$> getHomeDirectory
124+expandTilde p = return p
118-- Messages
125-- Messages
@@ -259,13 +266,14 @@ handleCommand (Expression ls) =
259handleCommand Help = outputTStrLn helpMessage
266handleCommand Help = outputTStrLn helpMessage
260handleCommand (Import moduleName) = modify (updateImports moduleName)
267handleCommand (Import moduleName) = modify (updateImports moduleName)
261handleCommand (LoadFile filePath) = do
268handleCommand (LoadFile filePath) = do
269+ absPath <- ioToState $ expandTilde filePath
262− exists <- ioToState $ doesFileExist filePath
270+ exists <- ioToState $ doesFileExist absPath
263 if exists then
271 if exists then
264− ioToState (loadModule filePath) >>= either outputTStrLn (modify . updateModules)
272+ either outputTStrLn (modify . updateModules) =<< ioToState (loadModule absPath)
266 outputTStrLn $ "Couldn't locate: " ++ filePath
274 outputTStrLn $ "Couldn't locate: " ++ filePath
267handleCommand Reload = do
275handleCommand Reload = do
268− (Right prelude) <- ioToState $ getPreludeFilename >>= loadModule
276+ (Right prelude) <- ioToState $ loadModule =<< getPreludeFilename
269 put (PSCI defaultImports prelude [])
277 put (PSCI defaultImports prelude [])
270handleCommand Unknown = outputTStrLn "Unknown command"
278handleCommand Unknown = outputTStrLn "Unknown command"