Safe Haskell | None |
---|
Simple interface for shell scripting-like tasks.
- data Shell a
- 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 ()
- 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
- isFile :: FilePath -> Shell Bool
- rm :: FilePath -> Shell ()
- mv :: FilePath -> FilePath -> Shell ()
- cp :: FilePath -> FilePath -> Shell ()
- file :: File a => FilePath -> a
- withTempFile :: String -> (FilePath -> Handle -> Shell a) -> Shell a
- withTempDirectory :: String -> (FilePath -> Shell a) -> Shell a
- inTempDirectory :: Shell a -> Shell a
- hPutStr :: Handle -> String -> Shell ()
- hPutStrLn :: Handle -> String -> Shell ()
- echo :: String -> Shell ()
- module System.FilePath
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.
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.
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.
withTempDirectory :: String -> (FilePath -> Shell a) -> Shell aSource
Create a temp directory in the standard system temp 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.
module System.FilePath