-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple interface for shell scripting in Haskell. -- -- Aims to simplify development of cross-platform shell scripts and -- similar things. @package shellmate @version 0.1.5 -- | Simple interface for shell scripting-like tasks. module Control.Shell -- | Monad for running shell commands. If a command fails, the entire -- computation is aborted unless mayFail is used. data Shell a class Guard guard a | guard -> a guard :: Guard guard a => String -> guard -> Shell a -- | Run a Shell computation. The program's working directory will be -- restored after executing the computation. shell :: Shell a -> IO (Either String a) -- | Perform an action that may fail without aborting the entire -- computation. Forces serialization. mayFail :: Shell a -> Shell (Either String a) -- | Attempt to run the first command. If the first command fails, run the -- second. Forces serialization of the first command. orElse :: Shell a -> Shell a -> Shell a -- | Run a computation with a new value for an environment variable. Note -- that this will *not* affect external commands spawned using -- liftIO or which directory is considered the system temp -- directory. withEnv :: String -> (String -> String) -> Shell a -> Shell a -- | Get the value of an environment variable. Returns the empty string if -- the variable doesn't exist. getEnv :: String -> Shell String -- | Get the value of an environment variable. Returns Nothing if the -- variable doesn't exist. lookupEnv :: String -> Shell (Maybe String) -- | Execute an external command. No globbing, escaping or other external -- shell magic is performed on either the command or arguments. The -- program's text output will be returned, and not echoed to the screen. run :: FilePath -> [String] -> String -> Shell String -- | Like run, but echoes the command's text output to the screen -- instead of returning it. run_ :: FilePath -> [String] -> String -> Shell () -- | Run an interactive process. runInteractive :: FilePath -> [String] -> Shell () -- | Run a program and return a boolean indicating whether the command -- succeeded, the output from stdout, and the output from stderr. This -- command will never fail. genericRun :: FilePath -> [String] -> String -> Shell (Bool, String, String) -- | Run a command with elevated privileges. sudo :: FilePath -> [String] -> String -> Shell String -- | Change working directory. cd :: FilePath -> Shell () -- | Recursively copy a directory. If the target is a directory that -- already exists, the source directory is copied into that directory -- using its current name. cpDir :: FilePath -> FilePath -> Shell () -- | Get the current working directory. pwd :: Shell FilePath -- | List the contents of a directory, sans . and '..'. ls :: FilePath -> Shell [FilePath] -- | Create a directory. Optionally create any required missing directories -- as well. mkdir :: Bool -> FilePath -> Shell () -- | Recursively remove a directory. Follows symlinks, so be careful. rmdir :: FilePath -> Shell () -- | Execute a command in the given working directory, then restore the -- previous working directory. inDirectory :: FilePath -> Shell a -> Shell a -- | Does the given path lead to a directory? isDirectory :: FilePath -> Shell Bool -- | Do something with the user's home directory. withHomeDirectory :: (FilePath -> Shell a) -> Shell a -- | Do something *in* the user's home directory. inHomeDirectory :: Shell a -> Shell a -- | Do something with the given application's data directory. withAppDirectory :: String -> (FilePath -> Shell a) -> Shell a -- | Do something *in* the given application's data directory. inAppDirectory :: FilePath -> Shell a -> Shell a -- | Perform an action on each file in the given directory. This function -- will traverse any subdirectories of the given as well. File paths are -- given relative to the given directory; the current working directory -- is not affected. forEachFile :: FilePath -> (FilePath -> Shell a) -> Shell [a] -- | Recursively copy a directory, but omit all files that do not match the -- give predicate. cpFiltered :: (FilePath -> Bool) -> FilePath -> FilePath -> Shell () -- | Does the given path lead to a file? isFile :: FilePath -> Shell Bool -- | Remove a file. rm :: FilePath -> Shell () -- | Rename a file. mv :: FilePath -> FilePath -> Shell () -- | Copy a file. Fails if the source is a directory. If the target is a -- directory, the source file is copied into that directory using its -- current name. cp :: FilePath -> FilePath -> Shell () file :: File a => FilePath -> a -- | Create a temp file in the standard system temp directory, do something -- with it, then remove it. withTempFile :: String -> (FilePath -> Handle -> Shell a) -> Shell a -- | Create a temp file in the standard system temp directory, do something -- with it, then remove it. withCustomTempFile :: FilePath -> (FilePath -> Handle -> Shell a) -> Shell a -- | Create a temp directory in the standard system temp directory, do -- something with it, then remove it. withTempDirectory :: String -> (FilePath -> Shell a) -> Shell a -- | Create a temp directory in given directory, do something with it, then -- remove it. withCustomTempDirectory :: FilePath -> (FilePath -> Shell a) -> Shell a -- | Performs a command inside a temporary directory. The directory will be -- cleaned up after the command finishes. inTempDirectory :: Shell a -> Shell a -- | IO.hPutStr lifted into Shell for convenience. hPutStr :: Handle -> String -> Shell () -- | IO.hPutStrLn lifted into Shell for convenience. hPutStrLn :: Handle -> String -> Shell () -- | putStrLn lifted into Shell for convenience. echo :: String -> Shell () -- | Lazy counterpart to monadic bind. To stream data from a command -- a to a command b, do 'a |> b'. (|>) :: Shell String -> (String -> Shell a) -> Shell a -- | Lift a computation from the IO monad. liftIO :: MonadIO m => forall a. IO a -> m a instance Typeable ShellException instance Show ShellException instance Guard a b => Guard (Shell a) b instance Guard Bool () instance Guard (Maybe a) a instance File (Shell String) instance File (String -> Shell ()) instance Functor Shell instance Applicative Shell instance MonadIO Shell instance Monad Shell instance Exception ShellException