git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Tilde expansion works.
commit5613d1b31e5c81ab8c99dcfa91c2191ec60c6567 authorjoneshf <jones3.hardy@gmail.com> dateThu 20 Feb 2014, 22:40 (13 years ago) parentccce756
2 files changed+14−6
psci/Main.hs+13−5 purescript.cabal+1−1
psci/Main.hs+13−5
@@ -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
purescript.cabal+1−1
@@ -83,7 +83,7 @@ executable psc
8383 ghc-options: -Wall -O2 -fno-warn-unused-do-bind
8484
8585executable psci
86− build-depends: base >=4 && <5, containers -any, directory -any,
86+ build-depends: base >=4 && <5, containers -any, directory -any, filepath -any,
8787 mtl -any, parsec -any, haskeline <=0.7.1.1, purescript -any,
8888 syb -any, transformers -any, utf8-string -any, process -any,
8989 xdg-basedir -any