Safe Haskell | None |
---|
Simple interface for shell scripting-like tasks.
- data Shell a
- class Guard guard a | guard -> a where
- class File a where
- shell :: Shell a -> IO (Either String a)
- mayFail :: Shell a -> Shell (Either String a)
- orElse :: Shell a -> Shell a -> Shell a
- withEnv :: String -> (String -> String) -> Shell a -> Shell a
- getEnv :: String -> Shell String
- lookupEnv :: String -> Shell (Maybe String)
- run :: FilePath -> [String] -> String -> Shell String
- run_ :: FilePath -> [String] -> String -> Shell ()
- runInteractive :: FilePath -> [String] -> Shell ()
- genericRun :: FilePath -> [String] -> String -> Shell (Bool, String, String)
- sudo :: FilePath -> [String] -> String -> Shell String
- cd :: FilePath -> Shell ()
- cpDir :: FilePath -> FilePath -> Shell ()
- pwd :: Shell FilePath
- ls :: FilePath -> Shell [FilePath]
- mkdir :: Bool -> FilePath -> Shell ()
- rmdir :: FilePath -> Shell ()
- inDirectory :: FilePath -> Shell a -> Shell a
- isDirectory :: FilePath -> Shell Bool
- withHomeDirectory :: (FilePath -> Shell a) -> Shell a
- inHomeDirectory :: Shell a -> Shell a
- withAppDirectory :: String -> (FilePath -> Shell a) -> Shell a
- inAppDirectory :: FilePath -> Shell a -> Shell a
- forEachFile :: FilePath -> (FilePath -> Shell a) -> Shell [a]
- forEachFile_ :: FilePath -> (FilePath -> Shell ()) -> Shell ()
- cpFiltered :: (FilePath -> Bool) -> FilePath -> FilePath -> Shell ()
- isFile :: FilePath -> Shell Bool
- rm :: FilePath -> Shell ()
- mv :: FilePath -> FilePath -> Shell ()
- cp :: FilePath -> FilePath -> Shell ()
- withTempFile :: String -> (FilePath -> Handle -> Shell a) -> Shell a
- withCustomTempFile :: FilePath -> (FilePath -> Handle -> Shell a) -> Shell a
- withTempDirectory :: String -> (FilePath -> Shell a) -> Shell a
- withCustomTempDirectory :: FilePath -> (FilePath -> Shell a) -> Shell a
- inTempDirectory :: Shell a -> Shell a
- hPutStr :: Handle -> String -> Shell ()
- hPutStrLn :: Handle -> String -> Shell ()
- hClose :: Handle -> Shell ()
- echo :: String -> Shell ()
- (|>) :: Shell String -> (String -> Shell a) -> Shell a
- module System.FilePath
- liftIO :: MonadIO m => forall a. IO a -> m a
Documentation
Monad for running shell commands. If a command fails, the entire
computation is aborted unless mayFail
is used.
shell :: Shell a -> IO (Either String a)Source
Run a Shell computation. The program's working directory will be restored after executing the computation.
mayFail :: Shell a -> Shell (Either String a)Source
Perform an action that may fail without aborting the entire computation. Forces serialization.
orElse :: Shell a -> Shell a -> Shell aSource
Attempt to run the first command. If the first command fails, run the second. Forces serialization of the first command.
withEnv :: String -> (String -> String) -> Shell a -> Shell aSource
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.
getEnv :: String -> Shell StringSource
Get the value of an environment variable. Returns the empty string if the variable doesn't exist.
lookupEnv :: String -> Shell (Maybe String)Source
Get the value of an environment variable. Returns Nothing if the variable doesn't exist.
run :: FilePath -> [String] -> String -> Shell StringSource
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 ()Source
Like run
, but echoes the command's text output to the screen instead of
returning it.
runInteractive :: FilePath -> [String] -> Shell ()Source
Run an interactive process.
genericRun :: FilePath -> [String] -> String -> Shell (Bool, String, String)Source
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.
cpDir :: FilePath -> FilePath -> Shell ()Source
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.
mkdir :: Bool -> FilePath -> Shell ()Source
Create a directory. Optionally create any required missing directories as well.
inDirectory :: FilePath -> Shell a -> Shell aSource
Execute a command in the given working directory, then restore the previous working directory.
isDirectory :: FilePath -> Shell BoolSource
Does the given path lead to a directory?
withHomeDirectory :: (FilePath -> Shell a) -> Shell aSource
Do something with the user's home directory.
inHomeDirectory :: Shell a -> Shell aSource
Do something *in* the user's home directory.
withAppDirectory :: String -> (FilePath -> Shell a) -> Shell aSource
Do something with the given application's data directory.
inAppDirectory :: FilePath -> Shell a -> Shell aSource
Do something *in* the given application's data directory.
forEachFile :: FilePath -> (FilePath -> Shell a) -> Shell [a]Source
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 ()) -> Shell ()Source
Like forEachFile
but only performs a side effect.
cpFiltered :: (FilePath -> Bool) -> FilePath -> FilePath -> Shell ()Source
Recursively copy a directory, but omit all files that do not match the give predicate.
cp :: FilePath -> FilePath -> Shell ()Source
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.
withTempFile :: String -> (FilePath -> Handle -> Shell a) -> Shell aSource
Create a temp file in the standard system temp directory, do something with it, then remove it.
withCustomTempFile :: FilePath -> (FilePath -> Handle -> Shell a) -> Shell aSource
Create a temp file in the standard system temp directory, do something with it, then remove it.
withTempDirectory :: String -> (FilePath -> Shell a) -> Shell aSource
Create a temp directory in the standard system temp directory, do something with it, then remove it.
withCustomTempDirectory :: FilePath -> (FilePath -> Shell a) -> Shell aSource
Create a temp directory in given directory, do something with it, then remove it.
inTempDirectory :: Shell a -> Shell aSource
Performs a command inside a temporary directory. The directory will be cleaned up after the command finishes.
(|>) :: Shell String -> (String -> Shell a) -> Shell aSource
Lazy counterpart to monadic bind. To stream data from a command a
to a
command b
, do 'a |> b'.
module System.FilePath