diff --git a/notebooks/Test.ipynb b/notebooks/Test.ipynb
index 50caafd6..05d38416 100644
--- a/notebooks/Test.ipynb
+++ b/notebooks/Test.ipynb
@@ -36,19 +36,31 @@
"cell_type": "code",
"collapsed": false,
"input": [
- "getStringTarget :: String -> String\n",
- "getStringTarget = go \"\" . reverse\n",
- " where\n",
- " go acc rest = case rest of\n",
- " '\"':'\\\\':rem -> go ('\"':acc) rem\n",
- " '\"':rem -> acc\n",
- " ' ':'\\\\':rem -> go (' ':acc) rem\n",
- " ' ':rem -> acc\n",
- " x:rem -> go (x:acc) rem\n",
- " [] -> acc\n",
- "\n",
- "\" ~/archive/\n",
- ":load \" ~/archive/"
+ "import System.Directory\n",
+ "getDirectoryContents \".\""
+ ],
+ "language": "python",
+ "metadata": {
+ "hidden": false
+ },
+ "outputs": [
+ {
+ "metadata": {},
+ "output_type": "display_data",
+ "text": [
+ "[\".\",\"..\",\".hdevtools.sock\",\"blog\",\"experiments\",\"hackathon\",\"haskell-course-preludes\",\"haskell-style-guide\",\"ihaskell\",\"ihaskell-app\",\"linal\",\"notes\",\"slinky.nb\",\"tasha\"]"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ ":!cd code\n",
+ ":!pwd\n",
+ "setCurrentDirectory \"code\""
],
"language": "python",
"metadata": {
@@ -57,37 +69,23 @@
"outputs": [
{
"html": [
- "Parse error (line 12, column 13): lexical error in string/character literal at end of input"
+ "No such directory: 'code'"
],
"metadata": {},
"output_type": "display_data",
"text": [
- "Parse error (line 12, column 13): lexical error in string/character literal at end of input"
+ "No such directory: 'code'"
]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "getStringTarget \"absdf\\\" he\\\\\\\"llo\""
- ],
- "language": "python",
- "metadata": {
- "hidden": false
- },
- "outputs": [
+ },
{
"metadata": {},
"output_type": "display_data",
"text": [
- "\"he\\\"llo\""
+ "/Users/silver/code"
]
}
],
- "prompt_number": 13
+ "prompt_number": 8
},
{
"cell_type": "code",
diff --git a/src/IHaskell/Eval/Evaluate.hs b/src/IHaskell/Eval/Evaluate.hs
index 8153c7b7..05f8ee66 100644
--- a/src/IHaskell/Eval/Evaluate.hs
+++ b/src/IHaskell/Eval/Evaluate.hs
@@ -106,6 +106,7 @@ globalImports :: [String]
globalImports =
[ "import IHaskell.Display()"
, "import qualified Prelude as IHaskellPrelude"
+ , "import qualified System.Directory as IHaskellDirectory"
, "import qualified IHaskell.Display"
, "import qualified IHaskell.IPython.Stdin"
, "import qualified System.Posix.IO as IHaskellIO"
@@ -498,24 +499,32 @@ evalCommand _ (Directive LoadFile name) state = wrapExecution state $ do
modName <- intercalate "." <$> getModuleName contents
doLoadModule filename modName
-evalCommand publish (Directive ShellCmd ('!':cmd)) state = wrapExecution state $ liftIO $
+evalCommand publish (Directive ShellCmd ('!':cmd)) state = wrapExecution state $
case words cmd of
"cd":dirs -> do
-- Get home so we can replace '~` with it.
- homeEither <- try $ getEnv "HOME" :: IO (Either SomeException String)
+ homeEither <- liftIO (try $ getEnv "HOME" :: IO (Either SomeException String))
let home = case homeEither of
Left _ -> "~"
Right val -> val
let directory = replace "~" home $ unwords dirs
- exists <- doesDirectoryExist directory
+ exists <- liftIO $ doesDirectoryExist directory
if exists
then do
- setCurrentDirectory directory
+ -- Set the directory in IHaskell native code, for future shell
+ -- commands. This doesn't set it for user code, though.
+ liftIO $ setCurrentDirectory directory
+
+ -- Set the directory for user code.
+ let cmd = printf "IHaskellDirectory.setCurrentDirectory \"%s\"" $
+ replace " " "\\ " $
+ replace "\"" "\\\"" directory
+ runStmt cmd RunToCompletion
return mempty
else
return $ displayError $ printf "No such directory: '%s'" directory
- cmd -> do
+ cmd -> liftIO $ do
(readEnd, writeEnd) <- createPipe
handle <- fdToHandle writeEnd
pipe <- fdToHandle readEnd