on master help sign in
Add :! for running shell commands from the REPL
d4ce631Ryan Scott
src/Idris/Completion.hs+1
@@ -159,6 +159,7 @@ completeColour (prev, next) = case words (reverse prev) of
159completeCmd :: String -> CompletionFunc Idris
159completeCmd :: String -> CompletionFunc Idris
160completeCmd cmd (prev, next) = fromMaybe completeCmdName $ fmap completeArg $ lookupInHelp cmd
160completeCmd cmd (prev, next) = fromMaybe completeCmdName $ fmap completeArg $ lookupInHelp cmd
161 where completeArg FileArg = completeFilename (prev, next)
161 where completeArg FileArg = completeFilename (prev, next)
162+ completeArg ShellCommandArg = completeFilename (prev, next)
162 completeArg NameArg = completeName UpTo [] (prev, next)
163 completeArg NameArg = completeName UpTo [] (prev, next)
163 completeArg OptionArg = completeOption (prev, next)
164 completeArg OptionArg = completeOption (prev, next)
164 completeArg ModuleArg = noCompletion (prev, next)
165 completeArg ModuleArg = noCompletion (prev, next)
src/Idris/Help.hs+2
@@ -11,6 +11,7 @@ module Idris.Help (CmdArg(..), extraHelp) where
11data CmdArg = ExprArg -- ^ The command takes an expression
11data CmdArg = ExprArg -- ^ The command takes an expression
12 | NameArg -- ^ The command takes a name
12 | NameArg -- ^ The command takes a name
13 | FileArg -- ^ The command takes a file
13 | FileArg -- ^ The command takes a file
14+ | ShellCommandArg -- ^ The command takes a shell command name
14 | ModuleArg -- ^ The command takes a module name
15 | ModuleArg -- ^ The command takes a module name
15 | PkgArgs -- ^ The command takes a list of package names
16 | PkgArgs -- ^ The command takes a list of package names
16 | NumberArg -- ^ The command takes a number
17 | NumberArg -- ^ The command takes a number
@@ -30,6 +31,7 @@ instance Show CmdArg where
30 show ExprArg = "<expr>"
31 show ExprArg = "<expr>"
31 show NameArg = "<name>"
32 show NameArg = "<name>"
32 show FileArg = "<filename>"
33 show FileArg = "<filename>"
34+ show ShellCommandArg = "<command>"
33 show ModuleArg = "<module>"
35 show ModuleArg = "<module>"
34 show PkgArgs = "<package list>"
36 show PkgArgs = "<package list>"
35 show NumberArg = "<number>"
37 show NumberArg = "<number>"
src/Idris/REPL.hs+2
@@ -590,6 +590,7 @@ splitName s = case reverse $ splitOn "." s of
590idemodeProcess :: FilePath -> Command -> Idris ()
590idemodeProcess :: FilePath -> Command -> Idris ()
591idemodeProcess fn Warranty = process fn Warranty
591idemodeProcess fn Warranty = process fn Warranty
592idemodeProcess fn Help = process fn Help
592idemodeProcess fn Help = process fn Help
593+idemodeProcess fn (RunShellCommand cmd) = process fn (RunShellCommand cmd)
593idemodeProcess fn (ChangeDirectory f) =
594idemodeProcess fn (ChangeDirectory f) =
594 do process fn (ChangeDirectory f)
595 do process fn (ChangeDirectory f)
595 dir <- runIO $ getCurrentDirectory
596 dir <- runIO $ getCurrentDirectory
@@ -817,6 +818,7 @@ insertScript prf (x : xs) = x : insertScript prf xs
817process :: FilePath -> Command -> Idris ()
818process :: FilePath -> Command -> Idris ()
818process fn Help = iPrintResult displayHelp
819process fn Help = iPrintResult displayHelp
819process fn Warranty = iPrintResult warranty
820process fn Warranty = iPrintResult warranty
821+process fn (RunShellCommand cmd) = runIO $ system cmd >> return ()
820process fn (ChangeDirectory f)
822process fn (ChangeDirectory f)
821 = do runIO $ setCurrentDirectory f
823 = do runIO $ setCurrentDirectory f
822 return ()
824 return ()
src/Idris/REPL/Commands.hs+1
@@ -17,6 +17,7 @@ data Command = Quit
17 | Reload
17 | Reload
18 | Watch
18 | Watch
19 | Load FilePath (Maybe Int) -- up to maximum line number
19 | Load FilePath (Maybe Int) -- up to maximum line number
20+ | RunShellCommand FilePath
20 | ChangeDirectory FilePath
21 | ChangeDirectory FilePath
21 | ModImport String
22 | ModImport String
22 | Edit
23 | Edit
src/Idris/REPL/Parser.hs+1
@@ -78,6 +78,7 @@ parserCommandsForHelp =
78 , noArgCmd ["w", "watch"] Watch "Watch the current file for changes"
78 , noArgCmd ["w", "watch"] Watch "Watch the current file for changes"
79 , (["l", "load"], FileArg, "Load a new file"
79 , (["l", "load"], FileArg, "Load a new file"
80 , strArg (\f -> Load f Nothing))
80 , strArg (\f -> Load f Nothing))
81+ , (["!"], ShellCommandArg, "Run a shell command", strArg RunShellCommand)
81 , (["cd"], FileArg, "Change working directory"
82 , (["cd"], FileArg, "Change working directory"
82 , strArg ChangeDirectory)
83 , strArg ChangeDirectory)
83 , (["module"], ModuleArg, "Import an extra module", moduleArg ModImport) -- NOTE: dragons
84 , (["module"], ModuleArg, "Import an extra module", moduleArg ModImport) -- NOTE: dragons