úÎÔ6ÏNC      !"#$%&'()*+,-./0123456789:;<=>?@ABportable provisional$John Goerzen <jgoerzen@complete.org> GThe main type for communicating between commands. All are expected to  be lazy.  HWrites the Channel to the given Handle. If the first parameter is True, C do this in a separate thread and close the handle afterwards. CD     portable provisional$John Goerzen <jgoerzen@complete.org>$EAA command that carries environment variable information with it. #This is a low-level interface; see  and  for more convenient interfaces. FG)An environment variable filter function. #This is a low-level interface; see  and  for more convenient  interfaces.  Different ways to get data from  .  F IO () runs, throws an exception on error, and sends stdout to stdout A IO String runs, throws an exception on error, reads stdout into I a buffer, and returns it as a string. Note: This output is not lazy.  IO [String]9 is same as IO String, but returns the results as lines. " Note: this output is not lazy. 8 IO ExitCode runs and returns an ExitCode with the exit G information. stdout is sent to stdout. Exceptions are not thrown. 5 IO (String, ExitCode) is like IO ExitCode, but also B 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. A IO (String, IO (String, ExitCode)) returns a String read lazily F and an IO action that, when evaluated, finishes up the process and B results in its exit status. This command returns immediately. ? IO (IO (String, ExitCode)) sends stdout to stdout but returns L immediately. It forks off the child but does not wait for it to finish.  You can use  to wait for the finish. D IO Int returns the exit code from a program directly. If a signal : caused the command to be reaped, returns 128 + SIGNUM. C IO Bool returns True if the program exited normally (exit code 0, 1 not stopped by a signal) and False otherwise. LTo address insufficient laziness, you can process anything that needs to be -processed lazily within the pipeline itself. =Runs 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, Cor 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: M 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 E the name of a program to run, and the second gives its arguments. F The shell is never involved. This is ideal for passing filenames, G since there is no security risk involving special shell characters.  A Handle -> Handle -> IO ()& function, which reads from the first # handle and write to the second. D 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), for commands that explicitly H read no input. Useful with closures. Useful when you want to avoid L reading stdin because something else already is. These have the unit as N part of the function because otherwise we would have conflicts with things 9 such as bare Strings, which represent a command name. Invoke a command.  The command The environment Where to read input from bReturns an action that, when evaluated, waits for the process to finish and returns an exit code. Type for the environment. GResult type for shell commands. The String is the text description of the command, not its output. HIJKL(How to we handle and external command. MDPipe the output of the first command into the input of the second. NOP:Evaluates the result codes and returns an overall status GEvaluates 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 ()/. This prevents you from having to cast to it 6all the time when you do not care about the result of  . The implementation is simply: (runIO :: (ShellCommand a) => a -> IO ()  runIO = run JAnother convenience function. This returns the first line of the output, Nwith any trailing newlines or whitespace stripped off. No leading whitespace Mis 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  B instance that returns a String, though that instance returns the (entirety of the output in that String. QLConvenience function to wrap a child thread. Kicks off the thread, handles /running the code, traps execptions, the works. @Note that if func is lazy, such as a getContents sort of thing, $the exception may go uncaught here. NOTE: expects func to be lazy! Description of this function  The action to run in the thread FSets an environment variable, replacing an existing one if it exists. Here'2s 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-8 Now, let' s set one:  E Prelude HSH> runIO $ setenv [("TERM", "foo")] $ "echo $TERM, $LANG"  foo, en_US.UTF-8 Or two:  h Prelude 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:  ^ Prelude HSH> runIO $ setenv [("TERM", "foo"), ("LANG", "de_DE.UTF-8")] $ "echo $TERM, $LANG"  foo, de_DE.UTF-8 "It can be combined with unsetenv:  Y Prelude HSH> runIO $ setenv [("TERM", "foo")] $ unsetenv ["LANG"] $ "echo $TERM, $LANG"  foo, And used with pipes:  V Prelude HSH> runIO $ setenv [("TERM", "foo")] $ "echo $TERM, $LANG" -|- "tr a-z A-Z"  FOO, EN_US.UTF-8  See also . FRemoves an environment variable if it exists; does nothing otherwise.  See also &, which has a more extensive example. RAn instance of S represeting a pipeline. TAn instance of S for an external command. The OString is split using words to the command to run, and the arguments, if any. UAn instance of S for an external command. The Kfirst String is the command to run, and the list of Strings represents the #arguments to the program, if any. VThe same for an IO function WAn instance of S% for a pure Haskell function mapping [String] to [String].  A [String]$ is generated from a Handle via the X function, and the reverse occurs via Y. ISo, this function is intended to operate upon lines of input and produce lines of output. ZAn instance of S% for a pure Haskell function mapping CString to String. Implement in terms of (String -> IO String) for  simplicity. [IA user function that takes no input, and generates output. We will deal .with it using hPutStr to send the output on.       portable provisional$John Goerzen <jgoerzen@complete.org>-=Return the absolute path of the arg. Raises an error if the computation is impossible. The filename part of a path The directory part of a path BChanges the current working directory to the given path, executes  the given I/7O action, then changes back to the original directory,  even if the I/O action raised an exception. DThis is an alias for the MissingH function System.Path.bracketCWD. :Load the specified files and display them, one at a time. The special file -2 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  . 8Copy data from input to output, optionally with a fixed Fmaximum 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) prior to calling 'this function for optimal performance.  See also ,   #Maximum amount of data to transfer Handle for input Generic version of ); reads data from specified Channel, and ignores stdin. Handle to read from #Maximum amount of data to transfer Handle for input (ignored) !GTakes input, writes it to the specified file, and does not pass it on. 5 The return value is the empty string. See also catToBS,  " "Like !8, but opens the destination in ReadWriteMode instead of KReadOnlyMode. Due to an oddity of the Haskell IO system, this is required Iwhen writing to a named pipe (FIFO) even if you will never read from it. BThis call will BLOCK all threads on open until a reader connects.  This is provided in addition to ! because you may want to cat to 8something that you do not have permission to read from. 4This function is only available on POSIX platforms.  See also ! \#Like !, but appends to the file. $3An alias for System.Directory.setCurrentDirectory. Want 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" &CRead all input and produce no output. Discards input completely. 'LSplit a list by a given character and select ranges of the resultant lists.  @ cutR [2..4] ' ' "foo bar baz quux foobar" -> "baz quux foobar" G cutR [1..1000] ' ' "foo bar baz quux foobar" -> "bar baz quux foobar" O cutR [-1000..1000] ' ' "foo bar baz quux foobar" -> "foo bar baz quux foobar" CNote that too large and too small indices are essentially ignored. (3Takes a string and sends it on as standard output. *The input to this function is never read. BYou 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. *FSearch for the regexp in the lines. Return those that do NOT match. +<Exits with the specified error code. 0 indicates no error. ,CTakes 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 list FThe result of a tilde expansion on a nonexistant username is to do no tilde expansion. 8The tilde with no username equates to the current user. FNon-tilde expansion is done by the MissingH module System.Path.Glob. ->Search for the string in the lines. Return those that match.  Same as: ) grep needle = filter (isInfixOf needle) .FSearch for the string in the lines. Return those that do NOT match. /Join lines of a file 0JCreates the given directory. A value of 0o755 for mode would be typical. 5An alias for System.Posix.Directory.createDirectory. ;The second argument will be ignored on non-POSIX systems. 1Number each line of a file 24An alias for System.Directory.getCurrentDirectory. 39Return the destination that the given symlink points to. 1An alias for System.Posix.Files.readSymbolicLink 5This function is only available on POSIX platforms. 4As 3., but turns the result into an absolute path. 5This function is only available on POSIX platforms. 5'Reverse characters on each line (rev) 6'Reverse characters on each line (rev) 7Reverse words on each line +Reverse lines in a String (like Unix tac). Implemented as:   tac = reverse See <. 8ETakes 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. BThis call will BLOCK all threads on open until a reader connects. 5This 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. <5Remove duplicate lines from a file (like Unix uniq). rTakes 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) ^_+ !"#$%&'()*+,-./0123456789:;<=>?@AB+# !"$%'&(+,-.)*/?@0123456=>789:;BA<) !"#$%&'()*+,-./0123456789:;<=>?@ABportable provisional%John Goerzen <jgoerzen@complete.org> 9  !"#$%&'()*+,-./0123456789:;<=>?@AB`      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIIJKLMNOPQRSTUVWXYZ[\]^\]_`abcdef HSH-2.0.3 HSH.Channel HSH.CommandHSH.ShellEquivsHSH Channelizable toChannelChannel ChanHandleChanBSL ChanString chanAsString chanAsBSLchanAsBS chanToHandle RunResultrun PipeCommand ShellCommandfdInvoke Environment InvokeResult-|- checkResultstryECcatchECrunIOrunSLsetenvunsetenvabspathbasenamedirname bracketCDcatFromcatBytes catBytesFromcatTo catToFIFOappendTocdcutdiscardcutRechoegrepegrepVexitglobgrepgrepV joinLinesmkdir numberLinespwdreadlink readlinkabsrevrevWtacteeteeFIFOtrtrduniqspaceunspacelowerupperwcLwcWstr2bslbsl2strEnvironCommand EnvironFilterddrgenericStringlikeIOgenericStringlikeOgenericCommand printCmdSpecintermediateStringlikeResultgenericStringlikeResultprocessResults runInHandler$fShellCommandPipeCommandprocess-1.1.0.0System.Process.Internals$fShellCommand[]$fShellCommand(,)$fShellCommand(->)0$fShellCommand(->)2base Data.Listlinesunlines$fShellCommand(->)9$fShellCommand(->)14fifoOpen teeBSGenericsplit splitpath