A module for shell-like programming in Haskell.
Shelly's focus is entirely on ease of use for those coming from shell scripting.
However, it also tries to use modern libraries and techniques to keep things efficient.
The functionality provided by
this module is (unlike standard Haskell filesystem functionality)
thread-safe: each Sh maintains its own environment and its own working
directory.
Recommended usage includes putting the following at the top of your program,
otherwise you will likely need either type annotations or type conversions
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly
import qualified Data.Text as T
default (T.Text)
Enter a Sh from (Monad)IO. The environment and working directories are
inherited from the current process-wide values. Any subsequent changes in
processwide working directory or environment are not reflected in the
running Sh.
Deprecated. Just use shelly. The default settings have changed
Deprecated now, just use shelly, whose default has been changed.
Using this entry point does not create a .shelly directory in the case
of failure. Instead it logs directly into the standard error stream (stderr).
Variadic argument version of run.
Please see the documenation for run.
The syntax is more convenient, but more importantly
it also allows the use of a FilePath as a command argument.
So an argument can be a Text or a FilePath without manual conversions.
a FilePath is automatically converted to Text with toTextIgnore.
Close the stream's file descriptor without
passing a Handle. On POSIX systems this may
lead to strange behavior in the child process
because attempting to read or write after the
file has been closed throws an error. This
should only be used with child processes that
don't use the file descriptor at all. If you
wish to ignore the child process's output you
should either create a pipe and drain it
manually or pass a Handle that writes to
/dev/null.
Instances2Eq, Show
EqStdStreamDefined in process-1.6.26.1 · System.Process.Common
ShowStdStreamDefined in process-1.6.26.1 · System.Process.Common
Lift a computation from the IO monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library
printState :: Show s => StateT s IO ()
printState = do
state <- get
liftIO $ print state
Had we omitted liftIO, we would have ended up with this error:
• Couldn't match type ‘IO’ with ‘StateT s IO’
Expected type: StateT s IO ()
Actual type: IO ()
The important part here is the mismatch between StateT s IO () and IO ().
Luckily, we know of a function that takes an IO a and returns an (m a): liftIO,
enabling us to run the program and see the expected results:
File and directory names are values of type String, whose precise
meaning is operating system dependent. Files can be opened, yielding a
handle which can then be used to operate on the contents of that file.
Instances1ToFilePath
ToFilePathFilePathDefined in shelly-1.12.1 · Shelly
List directory recursively (like the POSIX utility "find").
listing is relative if the path given is relative.
If you want to filter out some results or fold over them you can do that with the returned files.
A more efficient approach is to use one of the other find functions.
Similar to findWhen, but also filter out directories.
Alternatively, similar to findDirFilter, but also filter out files.
Filtering out directories makes the find much more efficient.