-- 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.2 -- | 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 data ExitReason Success :: ExitReason Failure :: !String -> ExitReason -- | Run a Shell computation. The program's working directory and -- environment will be restored after after the computation finishes. shell :: Shell a -> IO (Either ExitReason a) -- | Run a shell computation and discard its return value. If the -- computation fails, print its error message to stderr and -- exit. shell_ :: Shell a -> IO () -- | Convert an ExitReason into a String. Successful -- termination yields the empty string, while abnormal termination yields -- the termination error message. If the program terminaged abnormally -- but without an error message - i.e. the error message is empty string -- - the error message will be shown as "abnormal termination". exitString :: ExitReason -> String -- | 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 -- | Perform an action that may fail without aborting the entire -- computation. Forces serialization. If the inner computation terminates -- successfully, the outer computation terminates as well. try :: 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 -- | Terminate a computation, successfully. exit :: Shell a class Guard guard where type family Result guard -- | Perform a Shell computation; if the computation succeeds but returns a -- false-ish value, the outer Shell computation fails with the given -- error message. assert :: Guard guard => String -> guard -> Shell (Result guard) -- | Perform a Shell computation; if the computation succeeds but returns a -- false-ish value, the outer Shell computation fails. guard :: Guard g => g -> Shell (Result g) -- | Perform the given computation if the given guard passes, otherwise do -- nothing. when :: Guard g => g -> Shell a -> Shell () -- | Perform the given computation if the given guard fails, otherwise do -- nothing. unless :: Guard g => g -> Shell a -> Shell () -- | Set an environment variable. setEnv :: MonadIO m => String -> String -> m () -- | Get the value of an environment variable. Returns the empty string if -- the variable doesn't exist. getEnv :: String -> Shell String -- | 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 Nothing if the -- variable doesn't exist. lookupEnv :: String -> Shell (Maybe String) -- | The executable's command line arguments. cmdline :: [String] -- | Monads in which IO computations may be embedded. Any monad -- built by applying a sequence of monad transformers to the IO -- monad will be an instance of this class. -- -- Instances should satisfy the following laws, which state that -- liftIO is a transformer of monads: -- --
class Monad m => MonadIO (m :: * -> *) -- | Lift a computation from the IO monad. liftIO :: MonadIO m => IO a -> m a -- | Execute an external command. No globbing, escaping or other external -- shell magic is performed on either the command or arguments. The -- program's stdout 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 () -- | Like run, but always succeeds and returns the program's -- standard error stream and exit code. genericRun :: FilePath -> [String] -> String -> Shell (Int, String, String) -- | Run an interactive process. runInteractive :: FilePath -> [String] -> Shell () -- | Run a command with elevated privileges. sudo :: FilePath -> [String] -> String -> Shell String -- | Change working directory. cd :: MonadIO m => FilePath -> m () -- | 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 :: MonadIO m => m 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 :: MonadIO m => Bool -> FilePath -> m () -- | Recursively remove a directory. Follows symlinks, so be careful. rmdir :: MonadIO m => FilePath -> m () -- | 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 -- | Perform an action with the user's home directory as the working -- directory. inHomeDirectory :: Shell a -> Shell a -- | Do something with the given application's data directory. withAppDirectory :: String -> (FilePath -> Shell a) -> Shell a -- | Do something with the given application's data directory as the -- working 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] -- | Like forEachFile but only performs a side effect. forEachFile_ :: FilePath -> (FilePath -> Shell ()) -> Shell () -- | Recursively perform an action on each subdirectory of the given -- directory. The action will *not* be performed on the given directory -- itself. forEachDirectory :: FilePath -> (FilePath -> Shell a) -> Shell [a] -- | Like forEachDirectory, but discards its result. forEachDirectory_ :: FilePath -> (FilePath -> Shell ()) -> Shell () -- | Does the given path lead to a file? isFile :: FilePath -> Shell Bool -- | Remove a file. rm :: MonadIO m => FilePath -> m () -- | Rename a file. mv :: MonadIO m => FilePath -> FilePath -> m () -- | 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 () -- | Lazily read a file. input :: FilePath -> Shell String -- | Lazily write a file. output :: MonadIO m => FilePath -> String -> m () -- | 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 -- | Haskell defines operations to read and write characters from and to -- files, represented by values of type Handle. Each value of -- this type is a handle: a record used by the Haskell run-time -- system to manage I/O with file system objects. A handle has at -- least the following properties: -- --