on master help sign in
Add :! for running shell commands from the REPL
commitd4ce6316eda7695a515c3263cfdb1dfb41ba9fb8 authorRyan Scott <ryan.gl.scott@gmail.com> dateTue 24 Jan 2017, 11:24 (10 years ago) parentdc3d53f
5 files changed+7
src/Idris/Completion.hs+1 src/Idris/Help.hs+2 src/Idris/REPL.hs+2 src/Idris/REPL/Commands.hs+1 src/Idris/REPL/Parser.hs+1
src/Idris/Completion.hs+1
@@ -159,6 +159,7 @@ completeColour (prev, next) = case words (reverse prev) of
159159completeCmd :: String -> CompletionFunc Idris
160160completeCmd cmd (prev, next) = fromMaybe completeCmdName $ fmap completeArg $ lookupInHelp cmd
161161 where completeArg FileArg = completeFilename (prev, next)
162+ completeArg ShellCommandArg = completeFilename (prev, next)
162163 completeArg NameArg = completeName UpTo [] (prev, next)
163164 completeArg OptionArg = completeOption (prev, next)
164165 completeArg ModuleArg = noCompletion (prev, next)
src/Idris/Help.hs+2
@@ -11,6 +11,7 @@ module Idris.Help (CmdArg(..), extraHelp) where
1111data CmdArg = ExprArg -- ^ The command takes an expression
1212 | NameArg -- ^ The command takes a name
1313 | FileArg -- ^ The command takes a file
14+ | ShellCommandArg -- ^ The command takes a shell command name
1415 | ModuleArg -- ^ The command takes a module name
1516 | PkgArgs -- ^ The command takes a list of package names
1617 | NumberArg -- ^ The command takes a number
@@ -30,6 +31,7 @@ instance Show CmdArg where
3031 show ExprArg = "<expr>"
3132 show NameArg = "<name>"
3233 show FileArg = "<filename>"
34+ show ShellCommandArg = "<command>"
3335 show ModuleArg = "<module>"
3436 show PkgArgs = "<package list>"
3537 show NumberArg = "<number>"
src/Idris/REPL.hs+2
@@ -590,6 +590,7 @@ splitName s = case reverse $ splitOn "." s of
590590idemodeProcess :: FilePath -> Command -> Idris ()
591591idemodeProcess fn Warranty = process fn Warranty
592592idemodeProcess fn Help = process fn Help
593+idemodeProcess fn (RunShellCommand cmd) = process fn (RunShellCommand cmd)
593594idemodeProcess fn (ChangeDirectory f) =
594595 do process fn (ChangeDirectory f)
595596 dir <- runIO $ getCurrentDirectory
@@ -817,6 +818,7 @@ insertScript prf (x : xs) = x : insertScript prf xs
817818process :: FilePath -> Command -> Idris ()
818819process fn Help = iPrintResult displayHelp
819820process fn Warranty = iPrintResult warranty
821+process fn (RunShellCommand cmd) = runIO $ system cmd >> return ()
820822process fn (ChangeDirectory f)
821823 = do runIO $ setCurrentDirectory f
822824 return ()
src/Idris/REPL/Commands.hs+1
@@ -17,6 +17,7 @@ data Command = Quit
1717 | Reload
1818 | Watch
1919 | Load FilePath (Maybe Int) -- up to maximum line number
20+ | RunShellCommand FilePath
2021 | ChangeDirectory FilePath
2122 | ModImport String
2223 | Edit
src/Idris/REPL/Parser.hs+1
@@ -78,6 +78,7 @@ parserCommandsForHelp =
7878 , noArgCmd ["w", "watch"] Watch "Watch the current file for changes"
7979 , (["l", "load"], FileArg, "Load a new file"
8080 , strArg (\f -> Load f Nothing))
81+ , (["!"], ShellCommandArg, "Run a shell command", strArg RunShellCommand)
8182 , (["cd"], FileArg, "Change working directory"
8283 , strArg ChangeDirectory)
8384 , (["module"], ModuleArg, "Import an extra module", moduleArg ModImport) -- NOTE: dragons