packages feed

HSH 1.2.0 → 1.2.4

raw patch · 3 files changed

+70/−7 lines, 3 filesdep +filepathdep −FilePathdep ~MissingH

Dependencies added: filepath

Dependencies removed: FilePath

Dependency ranges changed: MissingH

Files

HSH.cabal view
@@ -1,5 +1,5 @@ Name: HSH-Version: 1.2.0+Version: 1.2.4 License: LGPL Maintainer: John Goerzen <jgoerzen@complete.org> Author: John Goerzen@@ -12,11 +12,11 @@ Description: HSH is designed to let you mix and match shell expressions with  Haskell programs. With HSH, it is possible to easily run shell  commands, capture their output or provide their input, and pipe them- to/from other shell commands and arbitrary Haskell functions at will.+ to and from other shell commands and arbitrary Haskell functions at will. Exposed-Modules: HSH, HSH.Command, HSH.ShellEquivs Extensions: ExistentialQuantification, OverlappingInstances,     UndecidableInstances-Build-Depends: base, unix, mtl, regex-compat, MissingH>=0.18.0, hslogger, FilePath, regex-base, regex-posix+Build-Depends: base, unix, mtl, regex-compat, MissingH>=0.18.3, hslogger, filepath, regex-base, regex-posix GHC-Options: -O2 Category: System 
HSH.hs view
@@ -26,11 +26,14 @@ >run $ "echo /etc/pass*" :: IO String > -> "/etc/passwd /etc/passwd-" >->run $ "ls -l" -|- "wc -l" :: IO ()+>runIO $ "ls -l" -|- "wc -l" > -> 12 >->run $ "ls -l" -|- wcL :: IO ()+>runIO $ "ls -l" -|- wcL > -> 12+>+>runIO $ ("ls", ["-l", "file with spaces.txt"])+>glob "~jgoerzen" >>= cd . head  wcL is a pure Haskell function defined in "HSH.ShellEquivs.wcL" as: 
HSH/ShellEquivs.hs view
@@ -24,16 +24,19 @@                        abspath,                        appendTo,                        basename,+                       bracketCD,                        dirname,                        catFrom,                        catTo,                        cd,                        echo,                        exit,+                       glob,                        grep,                        grepV,                        egrep,                        egrepV,+                       mkdir,                        pwd,                        readlink,                        readlinkabs,@@ -46,10 +49,15 @@ import Text.Regex import Control.Monad import Control.Exception(evaluate)-import System.Directory+import System.Directory hiding (createDirectory) import System.Posix.Files+import System.Posix.User+import System.Posix.Directory+import System.Posix.Types+import System.IO.Error import System.Path import System.Exit+import qualified System.Path.Glob as Glob  {- | Load the specified files and display them, one at a time.  @@ -133,7 +141,15 @@ pwd :: IO FilePath pwd = getCurrentDirectory -{- | An alias for System.Directory.setCurrentDirectory -}+{- | An alias for System.Directory.setCurrentDirectory.++Want to change to a user\'s home directory?  Try this: ++> glob "~jgoerzen" >>= cd . head ++See also 'bracketCD'.++-} cd :: FilePath -> IO () cd = setCurrentDirectory @@ -190,3 +206,47 @@ exit code      | code == 0 = exitWith ExitSuccess     | otherwise = exitWith (ExitFailure code)++{- | Takes 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++The result of a tilde expansion on a nonexistant username is to do no+tilde expansion.++The tilde with no username equates to the current user.++Non-tilde expansion is done by the MissingH module System.Path.Glob.+-}+glob :: FilePath -> IO [FilePath]+glob inp@('~':remainder) =+    catch expanduser (\_ -> Glob.glob inp)+    where (username, rest) = span (/= '/') remainder+          expanduser = +              do lookupuser <- +                     if username /= "" +                        then return username+                        else getEffectiveUserName+                 ue <- getUserEntryForName lookupuser+                 Glob.glob (homeDirectory ue ++ rest)+glob x = Glob.glob x++{- | 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.++This is an alias for the MissingH function System.Path.bracketCWD.+-}+bracketCD :: FilePath -> IO a -> IO a+bracketCD = bracketCWD++{- | Creates the given directory.  A value of 0o755 for mode would be typical.+An alias for System.Posix.Directory.createDirectory+-}+mkdir :: FilePath -> FileMode -> IO ()+mkdir = createDirectory