Safe Haskell | None |
---|---|
Language | Haskell2010 |
Shh provides a shell-like environment for Haskell.
Synopsis
- initInteractive :: IO ()
- exe :: (Unit a, ExecArgs a) => String -> a
- mkProc :: String -> [String] -> Proc ()
- runProc :: Proc a -> IO a
- data Proc a
- class PipeResult f where
- data Stream
- devNull :: Stream
- withReadSplit0 :: (NFData b, PipeResult io) => Proc a -> ([String] -> IO b) -> io b
- withReadLines :: (NFData b, PipeResult io) => Proc a -> ([String] -> IO b) -> io b
- withReadWords :: (NFData b, PipeResult io) => Proc a -> ([String] -> IO b) -> io b
- readProc :: PipeResult io => Proc a -> io String
- readTrim :: (Functor io, PipeResult io) => Proc a -> io String
- readSplit0 :: Proc () -> IO [String]
- readLines :: Proc () -> IO [String]
- readWords :: Proc () -> IO [String]
- readAuto :: Read a => Proc () -> IO a
- (<<<) :: PipeResult io => Proc a -> String -> io a
- (>>>) :: PipeResult io => String -> Proc a -> io a
- readWriteProc :: MonadIO io => Proc a -> String -> io String
- apply :: MonadIO io => Proc a -> String -> io String
- trim :: String -> String
- split0 :: String -> [String]
- data Failure = Failure {
- failureProg :: String
- failureArgs :: [String]
- failureCode :: Int
- ignoreFailure :: (Functor m, ProcFailure m) => Proc a -> m ()
- catchFailure :: ProcFailure m => Proc a -> m (Either Failure a)
- catchCode :: (Functor m, ProcFailure m) => Proc a -> m Int
- class ExecArg a where
- asArg :: a -> [String]
- asArgFromList :: [a] -> [String]
- data ExecReference
- load :: ExecReference -> [String] -> Q [Dec]
- loadEnv :: ExecReference -> Q [Dec]
- loadAnnotated :: ExecReference -> (String -> String) -> [String] -> Q [Dec]
- loadAnnotatedEnv :: ExecReference -> (String -> String) -> Q [Dec]
- loadExe :: ExecReference -> String -> Q [Dec]
- loadExeAs :: ExecReference -> String -> String -> Q [Dec]
Documentation
initInteractive :: IO () Source #
This function needs to be called in order to use the library succesfully from GHCi.
Constructing a Proc
You will rarely have to use these as most of the time these are
created for you by using the loadEnv
template Haskell function.
mkProc :: String -> [String] -> Proc () Source #
Create a Proc
from a command and a list of arguments.
Type representing a series or pipeline (or both) of shell commands.
Instances
Monad Proc Source # | |
Functor Proc Source # | |
Applicative Proc Source # | |
MonadIO Proc Source # | |
Defined in Shh.Internal | |
ProcFailure Proc Source # | |
Defined in Shh.Internal | |
PipeResult Proc Source # | |
Defined in Shh.Internal (|>) :: Proc a -> Proc a -> Proc a Source # (<|) :: Proc a -> Proc a -> Proc a Source # (|!>) :: Proc a -> Proc a -> Proc a Source # (&>) :: Proc a -> Stream -> Proc a Source # (&!>) :: Proc a -> Stream -> Proc a Source # writeProc :: Proc a -> String -> Proc a Source # withRead :: NFData b => Proc a -> (String -> IO b) -> Proc b Source # | |
Semigroup (Proc a) Source # | The |
a ~ () => Monoid (Proc a) Source # | |
ExecArgs (Proc ()) Source # | |
Piping and Redirection
class PipeResult f where Source #
This class is used to allow most of the operators in Shh to be
polymorphic in their return value. This makes using them in an IO
context easier (we can avoid having to prepend everything with a
runProc
).
(|>) :: Proc a -> Proc a -> f a Source #
Use this to send the output of on process into the input of another. This is just like a shells `|` operator.
The result is polymorphic in it's output, and can result in either another `Proc a` or an `IO a` depending on the context in which it is used.
>>>
echo "Hello" |> wc
1 1 6
(<|) :: Proc a -> Proc a -> f a Source #
Flipped version of |>
(|!>) :: Proc a -> Proc a -> f a Source #
Similar to |!>
except that it connects stderr to stdin of the
next process in the chain.
NB: The next command to be |>
on will recapture the stdout of
both preceding processes, because they are both going to the same
handle!
This is probably not what you want, see the &>
and &!>
operators
for redirection.
(&>) :: Proc a -> Stream -> f a Source #
Redirect stdout of this process to another location
ls &> Append "/dev/null"
(&!>) :: Proc a -> Stream -> f a Source #
Redirect stderr of this process to another location
ls &!> StdOut
writeProc :: Proc a -> String -> f a Source #
withRead :: NFData b => Proc a -> (String -> IO b) -> f b Source #
Run a process and capture it's output lazily. Once the continuation is completed, the handles are closed, and the process is terminated.
Instances
PipeResult IO Source # | |
Defined in Shh.Internal (|>) :: Proc a -> Proc a -> IO a Source # (<|) :: Proc a -> Proc a -> IO a Source # (|!>) :: Proc a -> Proc a -> IO a Source # (&>) :: Proc a -> Stream -> IO a Source # (&!>) :: Proc a -> Stream -> IO a Source # writeProc :: Proc a -> String -> IO a Source # withRead :: NFData b => Proc a -> (String -> IO b) -> IO b Source # | |
PipeResult Proc Source # | |
Defined in Shh.Internal (|>) :: Proc a -> Proc a -> Proc a Source # (<|) :: Proc a -> Proc a -> Proc a Source # (|!>) :: Proc a -> Proc a -> Proc a Source # (&>) :: Proc a -> Stream -> Proc a Source # (&!>) :: Proc a -> Stream -> Proc a Source # writeProc :: Proc a -> String -> Proc a Source # withRead :: NFData b => Proc a -> (String -> IO b) -> Proc b Source # |
withReadSplit0 :: (NFData b, PipeResult io) => Proc a -> ([String] -> IO b) -> io b Source #
withReadLines :: (NFData b, PipeResult io) => Proc a -> ([String] -> IO b) -> io b Source #
Like
except it splits the string with withRead
first.lines
NB: Please consider using
where you can.withReadSplit0
withReadWords :: (NFData b, PipeResult io) => Proc a -> ([String] -> IO b) -> io b Source #
Strict reads
readTrim :: (Functor io, PipeResult io) => Proc a -> io String Source #
Like readProc
, but trim leading and tailing whitespace.
readSplit0 :: Proc () -> IO [String] Source #
A convinience function for reading in a "\NUL"
seperated list of
strings. This is commonly used when dealing with paths.
readSplit0 $ find "-print0"
readLines :: Proc () -> IO [String] Source #
A convinience function for reading the output lines of a Proc
.
Note: Please consider using
instead if you can.readSplit0
Writing to stdin
readWriteProc :: MonadIO io => Proc a -> String -> io String Source #
Read and write to a Proc
. Same as
readProc proc <<< input
apply :: MonadIO io => Proc a -> String -> io String Source #
Some as readWriteProc
. Apply a Proc
to a String
.
>>>
apply shasum "Hello"
"f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0 -\n"
String manipulation
Utility functions for dealing with common string issues in shell scripting.
split0 :: String -> [String] Source #
Function that splits '\0' seperated list of strings. Useful in conjuction
with find . "-print0"
.
Exceptions
If any exception is allowed to propagate out of a pipeline, all the
processes comprising the pipeline will be terminated. This is contrary
to how a shell normally works (even with -o pipefail
!).
When a process exits with a non-zero exit code we throw this Failure exception.
The only exception to this is when a process is terminated by SIGPIPE in a pipeline, in which case we ignore it.
Failure | |
|
Instances
Eq Failure Source # | |
Ord Failure Source # | |
Show Failure Source # | |
Exception Failure Source # | |
Defined in Shh.Internal toException :: Failure -> SomeException # fromException :: SomeException -> Maybe Failure # displayException :: Failure -> String # |
ignoreFailure :: (Functor m, ProcFailure m) => Proc a -> m () Source #
catchFailure :: ProcFailure m => Proc a -> m (Either Failure a) Source #
catchCode :: (Functor m, ProcFailure m) => Proc a -> m Int Source #
Run an Proc
action returning the return code if an
exception was thrown, and 0 if it wasn't.
Constructing Arguments
class ExecArg a where Source #
A class for things that can be converted to arguments on the command
line. The default implementation is to use show
.
Nothing
asArg :: a -> [String] Source #
asArg :: Show a => a -> [String] Source #
asArgFromList :: [a] -> [String] Source #
asArgFromList :: Show a => [a] -> [String] Source #
Template Haskell helpers
data ExecReference Source #
Specify how executables should be referenced.
Absolute | Find executables on PATH, but store their absolute path |
SearchPath | Always search on PATH |
load :: ExecReference -> [String] -> Q [Dec] Source #
Load the given executables into the program, checking their executability
and creating a function missingExecutables
to do a runtime check for their
availability.
loadEnv :: ExecReference -> Q [Dec] Source #
Scans your '$PATH' environment variable and creates a function for each
executable found. Binaries that would not create valid Haskell identifiers
are ignored. It also creates the IO action missingExecutables
which will
do a runtime check to ensure all the executables that were found at
compile time still exist.
loadAnnotated :: ExecReference -> (String -> String) -> [String] -> Q [Dec] Source #
Same as load
, but allows you to modify the function names.
loadAnnotatedEnv :: ExecReference -> (String -> String) -> Q [Dec] Source #
Like loadEnv
, but allows you to modify the function name that would
be generated.