xC      !"#$%&'()*+,-./0123456789:;<=>?@AB$Copyright (C) 2006-2009 John GoerzenGNU LGPL, version 2.1 or above$John Goerzen <jgoerzen@complete.org> provisionalportableNone234:MPThe main type for communicating between commands. All are expected to be lazy. Writes the Channel to the given Handle. If the first parameter is True, do this in a separate thread and close the handle afterwards. CDEFGH     CDEFGH$Copyright (C) 2006-2009 John GoerzenGNU LGPL, version 2.1 or above$John Goerzen <jgoerzen@complete.org> provisionalportableNone *234:MI@A command that carries environment variable information with it.#This is a low-level interface; see  and ! for more convenient interfaces. J(An environment variable filter function.#This is a low-level interface; see  and ! for more convenient interfaces.  Different ways to get data from  . DIO () runs, throws an exception on error, and sends stdout to stdoutIO String runs, throws an exception on error, reads stdout into a buffer, and returns it as a string. Note: This output is not lazy.eIO [String] is same as IO String, but returns the results as lines. Note: this output is not lazy.}IO ExitCode runs and returns an ExitCode with the exit information. stdout is sent to stdout. Exceptions are not thrown.IO (String, ExitCode) is like IO ExitCode, but also includes a description of the last command in the pipe to have an error (or the last command, if there was no error).;IO ByteString and are similar to their String counterparts.IO (String, IO (String, ExitCode)) returns a String read lazily and an IO action that, when evaluated, finishes up the process and results in its exit status. This command returns immediately.IO (IO (String, ExitCode)) sends stdout to stdout but returns immediately. It forks off the child but does not wait for it to finish. You can use  to wait for the finish.|IO Int returns the exit code from a program directly. If a signal caused the command to be reaped, returns 128 + SIGNUM.rIO Bool returns True if the program exited normally (exit code 0, not stopped by a signal) and False otherwise.xTo address insufficient laziness, you can process anything that needs to be processed lazily within the pipeline itself. eRuns a command (or pipe of commands), with results presented in any number of different ways. A shell command is something we can invoke, pipe to, pipe from, or pipe in both directions. All commands that can be run as shell commands must define these methods.Minimum implementation is .#Some pre-defined instances include:A simple bare string, which is passed to the shell for execution. The shell will then typically expand wildcards, parse parameters, etc.A (String, [String]) tuple. The first item in the tuple gives the name of a program to run, and the second gives its arguments. The shell is never involved. This is ideal for passing filenames, since there is no security risk involving special shell characters.A Handle -> Handle -> IO ()H function, which reads from the first handle and write to the second.Various functions. These functions will accept input representing its standard input and output will go to standard output. ,Some pre-defined instance functions include:(String -> String), (String -> IO String)/, plus the same definitions for ByteStrings.([String] -> [String]), ([String] -> IO [String]) , where each String( in the list represents a single line(() -> String), (() -> IO String)9, for commands that explicitly read no input. Useful with closures. Useful when you want to avoid reading stdin because something else already is. These have the unit as part of the function because otherwise we would have conflicts with things such as bare Strings, which represent a command name.Invoke a command. Type for the environment. dResult type for shell commands. The String is the text description of the command, not its output. K'How to we handle and external command. CPipe the output of the first command into the input of the second. L9Evaluates the result codes and returns an overall status FEvaluates result codes and raises an error for any bad ones it finds. >Handle an exception derived from a program exiting abnormally =Catch an exception derived from a program exiting abnormally 7A convenience function. Refers only to the version of   that returns IO ()e. This prevents you from having to cast to it all the time when you do not care about the result of  .The implementation is simply: 3runIO :: (ShellCommand a) => a -> IO () runIO = run"Another convenience function. This returns the first line of the output, with any trailing newlines or whitespace stripped off. No leading whitespace is stripped. This function will raise an exception if there is not at least one line of output. Mnemonic: runSL means "run single line".$This command exists separately from   because there is already a  i instance that returns a String, though that instance returns the entirety of the output in that String. MzConvenience function to wrap a child thread. Kicks off the thread, handles running the code, traps execptions, the works.cNote that if func is lazy, such as a getContents sort of thing, the exception may go uncaught here.NOTE: expects func to be lazy!ESets an environment variable, replacing an existing one if it exists.^Here's a sample ghci session to illustrate. First, let's see the defaults for some variables: ;Prelude HSH> runIO $ "echo $TERM, $LANG" xterm, en_US.UTF-8Now, let's set one: TPrelude HSH> runIO $ setenv [("TERM", "foo")] $ "echo $TERM, $LANG" foo, en_US.UTF-8Or two: wPrelude HSH> runIO $ setenv [("TERM", "foo")] $ setenv [("LANG", "de_DE.UTF-8")] $ "echo $TERM, $LANG" foo, de_DE.UTF-8&We could also do it easier, like this: mPrelude HSH> runIO $ setenv [("TERM", "foo"), ("LANG", "de_DE.UTF-8")] $ "echo $TERM, $LANG" foo, de_DE.UTF-8!It can be combined with unsetenv: \Prelude HSH> runIO $ setenv [("TERM", "foo")] $ unsetenv ["LANG"] $ "echo $TERM, $LANG" foo,And used with pipes: ePrelude HSH> runIO $ setenv [("TERM", "foo")] $ "echo $TERM, $LANG" -|- "tr a-z A-Z" FOO, EN_US.UTF-8 See also .ERemoves an environment variable if it exists; does nothing otherwise. See also %, which has a more extensive example.NAn instance of  represeting a pipeline. OAn instance of m for an external command. The String is split using words to the command to run, and the arguments, if any. PAn instance of  for an external command. The first String is the command to run, and the list of Strings represents the arguments to the program, if any. QThe same for an IO function RAn instance of : for a pure Haskell function mapping [String] to [String]..A [String] is generated from a Handle via the S& function, and the reverse occurs via T.ZSo, this function is intended to operate upon lines of input and produce lines of output. UAn instance of t for a pure Haskell function mapping String to String. Implement in terms of (String -> IO String) for simplicity. VvA user function that takes no input, and generates output. We will deal with it using hPutStr to send the output on. SIWJ  The commandThe environmentWhere to read input fromaReturns an action that, when evaluated, waits for the process to finish and returns an exit code.XYZ[\K]^_LMDescription of this functionThe action to run in the thread`abcdefghijklmnNOPoQpRqrstuvwxyzU{|}~V   OIWJ   XYZ[\K]^_LM`abcdefghijklmnNOPoQpRqrstuvwxyzU{|}~VCopyright (C) 2009 John GoerzenGNU LGPL, version 2.1 or above$John Goerzen <jgoerzen@complete.org> provisionalportableNone3:M)Return the absolute path of the arg. Raises an error if the computation is impossible. This is a thin wrapper around System.Path.absNormPath. Unix/Linux users note: System.Path.absNormPath is known to produce odd results when a tilde expansion is requested; you might prefer ,J to this function if you know your input is free of wildcards. See https:/ github.comjgoerzenhshissues/7 for details. The filename part of a path The directory part of a path Changes the current working directory to the given path, executes the given I/O action, then changes back to the original directory, even if the I/O action raised an exception.CThis is an alias for the MissingH function System.Path.bracketCWD. 9Load the specified files and display them, one at a time.The special file -O means to display the input. If it is not given, no input is processed at all.-$ may be given a maximum of one time. See also  . Copy data from input to output, optionally with a fixed maximum size, in bytes. Processes data using ByteStrings internally, so be aware of any possible UTF-8 conversions.You may wish to use (hSetBuffering h (BlockBuffering Nothing)8 prior to calling this function for optimal performance. See also ,   Generic version of 7; reads data from specified Channel, and ignores stdin.!|Takes input, writes it to the specified file, and does not pass it on. The return value is the empty string. See also catToBS, " "Like !, but opens the destination in ReadWriteMode instead of ReadOnlyMode. Due to an oddity of the Haskell IO system, this is required when writing to a named pipe (FIFO) even if you will never read from it.AThis call will BLOCK all threads on open until a reader connects. This is provided in addition to !W because you may want to cat to something that you do not have permission to read from.3This function is only available on POSIX platforms. See also ! #Like !, but appends to the file. $2An alias for System.Directory.setCurrentDirectory.5Want to change to a user's home directory? Try this: glob "~jgoerzen" >>= cd . head See also .%:Split a list by a given character and select the nth list. %cut ' ' 2 "foo bar baz quux" -> "bar"&BRead all input and produce no output. Discards input completely. 'KSplit a list by a given character and select ranges of the resultant lists. cutR [2..4] ' ' "foo bar baz quux foobar" -> "baz quux foobar" cutR [1..1000] ' ' "foo bar baz quux foobar" -> "bar baz quux foobar" cutR [-1000..1000] ' ' "foo bar baz quux foobar" -> "foo bar baz quux foobar"BNote that too large and too small indices are essentially ignored.(2Takes a string and sends it on as standard output.)The input to this function is never read.AYou can pass this thing a String, a ByteString, or even a Handle. See also echoBS. )>Search for the regexp in the lines. Return those that match. *ESearch for the regexp in the lines. Return those that do NOT match. +;Exits with the specified error code. 0 indicates no error. ,KTakes a pattern. Returns a list of names that match that pattern. Handles: ~username at beginning of file to expand to user's home dir ? matches exactly one character * matches zero or more characters [list] matches any character in list [!list] matches any character not in listVThe result of a tilde expansion on a nonexistant username is to do no tilde expansion.7The tilde with no username equates to the current user.ENon-tilde expansion is done by the MissingH module System.Path.Glob. -FSearch for the string in the lines. Return those that match. Same as: 'grep needle = filter (isInfixOf needle).ESearch for the string in the lines. Return those that do NOT match. /Join lines of a file0ICreates the given directory. A value of 0o755 for mode would be typical.4An alias for System.Posix.Directory.createDirectory.:The second argument will be ignored on non-POSIX systems. 1Number each line of a file 23An alias for System.Directory.getCurrentDirectory. 38Return the destination that the given symlink points to.0An alias for System.Posix.Files.readSymbolicLink4This function is only available on POSIX platforms. 4As 3-, but turns the result into an absolute path.4This function is only available on POSIX platforms. 5&Reverse characters on each line (rev) 6Reverse words on each line &Reverse characters on each line (rev) 7*Reverse lines in a String (like Unix tac).Implemented as:  tac = reverseSee <. 8XTakes input, writes it to all the specified files, and passes it on. This function does NOT buffer input. See also . 9FIFO-safe version of 8.AThis call will BLOCK all threads on open until a reader connects.4This function is only available on POSIX platforms. :#Translate a character x to y, like:  tr 'e' 'f' Or, in sed, y//;(Delete specified character in a string. <4Remove duplicate lines from a file (like Unix uniq).qTakes a String representing a file or output and plugs it through lines and then nub to uniqify on a line basis. =:Double space a file; add an empty line between each line. >Inverse of double =; drop all empty lines. ?#Convert a string to all lower case @#Convert a string to all upper case A#Count number of lines. Like wc -l B-Count number of words in a file (like wc -w) -"Maximum amount of data to transferHandle for input Handle to read from"Maximum amount of data to transferHandle for input (ignored)!"#$%&'()*+,-./0123456789:;<=>?@AB+ !"#$%&'()*+,-./0123456789:;<=>?@AB+# !"$%'&(+,-.)*/?@0123456=>789:;BA<- !"#$%&'()*+,-./0123456789:;<=>?@ABCopyright (C) 2006 John GoerzenGNU LGPL, version 2.1 or above%John Goerzen <jgoerzen@complete.org>  provisionalportableNone3:M9  !"#$%&'()*+,-./0123456789:;<=>?@AB      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYWXZ[\M]^_`abcdefghijklmnopqrstuvwxyz{|}~ HSH-2.1.2 HSH.Channel HSH.CommandHSH.ShellEquivsHSH Channelizable toChannelChannel ChanHandleChanBSL ChanString chanAsString chanAsBSLchanAsBS chanToHandle RunResultrun PipeCommand ShellCommandfdInvoke Environment InvokeResult-|- checkResultstryECcatchECrunIOrunSLsetenvunsetenvabspathbasenamedirname bracketCDcatFromcatBytes catBytesFromcatTo catToFIFOappendTocdcutdiscardcutRechoegrepegrepVexitglobgrepgrepV joinLinesmkdir numberLinespwdreadlink readlinkabsrevrevWtacteeteeFIFOtrtrduniqspaceunspacelowerupperwcLwcWstr2bslbsl2str$fChannelizableByteString$fChannelizableHandle$fChannelizableByteString0$fChannelizable[]EnvironCommand EnvironFiltergenericCommandprocessResults runInHandler$fShellCommandPipeCommand$fShellCommand[]$fShellCommand(,)$fShellCommand(->)0$fShellCommand(->)2base Data.Listlinesunlines$fShellCommand(->)9$fShellCommand(->)14ddremgenericStringlikeIOgenericStringlikeO printCmdSpecintermediateStringlikeResultgenericStringlikeResult$fShellCommandEnvironCommand $fShow(->) $fRunResultIO$fRunResultIO0$fRunResultIO1$fRunResultIO2$fRunResultIO3$fRunResultIO4$fRunResultIO5$fRunResultIO6$fRunResultIO7$fRunResultIO8$fRunResultIO9$fRunResultIO10$fRunResultIO11$fShellCommand(->)$fShellCommand(->)1 $fShow(->)0 $fShow(->)1 $fShow(->)2 $fShow(->)3$fShellCommand(->)3$fShellCommand(->)4$fShellCommand(->)5$fShellCommand(->)6$fShellCommand(->)7$fShellCommand(->)8$fShellCommand(->)10$fShellCommand(->)11$fShellCommand(->)12$fShellCommand(->)13$fShellCommand(->)15 $fShow(->)4 $fShow(->)5 $fShow(->)6 $fShow(->)7 $fShow(->)8 $fShow(->)9 $fShow(->)10 $fShow(->)11 $fShow(->)12 $fShow(->)13 $fShow(->)14 $fShow(->)15 $fShow(->)16 $fShow(->)17fifoOpen teeBSGenericsplit splitpath