HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleshelly-1.12.1Haskell2010

Shelly.Lifted

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)
  • 6 types
  • 4 classes
  • 115 values
  • Packageshelly-1.12.1
  • Exports126
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceLifted.hs
classclass Monad m => MonadSh (m :: Type -> Type) where
#

Methods

Instances12MonadSh, …
classclass Monad m => MonadShControl (m :: Type -> Type) where
#

Associated types

Methods

Instances11MonadShControl, …

Entering Sh

17 declarations
newtypenewtype Sh a
#
Instances17Monad, Functor, MonadFail, Applicative, MonadIO, MonadCatch, …
typetype ShIO a = Sh a
#

Deprecated. Use Sh instead of ShIO

ShIO is Deprecated in favor of Sh, which is easier to type.

valueshelly :: MonadIO m => Sh a -> m a
#

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.

valueshellyNoDir :: MonadIO m => Sh a -> m a
#

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).

valueshellyFailDir :: MonadIO m => Sh a -> m a
#

Using this entry point creates a .shelly directory in the case of failure where errors are recorded.

Running external commands

17 declarations
valuecmd :: ShellCmd result => FilePath -> result
#

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.

Convenient usage of cmd requires the following:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly
import qualified Data.Text as T
default (T.Text)
classclass ShellCmd t where
#

For the variadic function cmd.

Partially applied variadic functions require type signatures.

Methods

Instances6ShellCmd
classclass CmdArg a where
#

Argument converter for the variadic argument version of run called cmd. Useful for a type signature of a function that uses cmd.

Methods

Instances3CmdArg

Running commands Using handles

6 declarations
valuetransferFoldHandleLines
  1. :: a
  2. -> FoldCallback a
  3. -> Handle
  4. -> Text -> IO ()
  5. -> IO a
#

Transfer from one handle to another For example, send contents of a process output to stdout. Does not close the write handle.

Also, fold over the contents being streamed line by line.

datadata StdStream
#

Constructors

  • Inherit

    Inherit Handle from parent

  • UseHandle Handle

    Use the supplied Handle

  • CreatePipe

    Create a new pipe. The returned Handle will use the default encoding and newline translation mode (just like Handles created by openFile).

  • NoStream

    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
  • Eq StdStreamDefined in process-1.6.26.1 · System.Process.Common
  • Show StdStreamDefined in process-1.6.26.1 · System.Process.Common

Modifying and querying environment

6 declarations

Environment directory

4 declarations

Printing

10 declarations

Querying filesystem

8 declarations

Filename helpers

8 declarations
value(</>)
  1. :: (ToFilePath filepath1, ToFilePath filepath2)
  2. => filepath1
  3. -> filepath2
  4. -> FilePath
#

Uses System.FilePath, but can automatically convert a Text.

Manipulating filesystem

9 declarations

reading/writing Files

6 declarations

exiting the program

4 declarations

Exceptions

8 declarations
valuebracket_sh :: Sh a -> (a -> Sh b) -> (a -> Sh c) -> Sh c
#

Deprecated. use Control.Exception.Lifted.bracket instead

valuefinally_sh :: Sh a -> Sh b -> Sh a
#

Deprecated. use Control.Exception.Lifted.finally instead

convert between Text and FilePath

3 declarations

Utility Functions

4 declarations
valuewhenM :: Monad m => m Bool -> m () -> m ()
#

A monadic-conditional version of the when guard.

Re-exported for your convenience

5 declarations
methodliftIO :: IO a -> m a
#

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:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3
valuewhen :: Applicative f => Bool -> f () -> f ()
#

Conditional execution of Applicative expressions. For example,

Examples
when debug (putStrLn "Debugging")

will output the string Debugging if the Boolean value debug is True, and otherwise do nothing.

Example1 expression
putStr "pi:" >> when False (print 3.14159)pi:
valueunless :: Applicative f => Bool -> f () -> f ()
#

The reverse of when.

Examples
Example1 expression
do x <- getLine       unless (x == "hi") (putStrLn "hi!")comingupwithexamplesisdifficulthi!
Example1 expression
unless (pi > exp 1) NothingJust ()
typetype FilePath = String
#

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
  • ToFilePath FilePathDefined in shelly-1.12.1 · Shelly
value(<$>) :: Functor f => (a -> b) -> f a -> f b
#

An infix synonym for fmap.

The name of this operator is an allusion to $. Note the similarities between their types:

 ($)  ::              (a -> b) ->   a ->   b
(<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas $ is function application, <$> is function application lifted over a Functor.

Examples

Convert from a Maybe Int to a Maybe String using show:

Example1 expression
show <$> NothingNothing
Example1 expression
show <$> Just 3Just "3"

Convert from an Either Int Int to an Either Int String using show:

Example1 expression
show <$> Left 17Left 17
Example1 expression
show <$> Right 17Right "17"

Double each element of a list:

Example1 expression
(*2) <$> [1,2,3][2,4,6]

Apply even to the second element of a pair:

Example1 expression
even <$> (2,2)(2,True)

internal functions for writing extensions

2 declarations

find functions

7 declarations
valuefind :: FilePath -> Sh [FilePath]
#

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.

Orphan instances

3 instances