packages feed

hscrtmpl 1.2 → 1.3

raw patch · 7 files changed

+245/−82 lines, 7 filesdep +regex-compatdep −old-locale

Dependencies added: regex-compat

Dependencies removed: old-locale

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright Dino Morelli 2013+Copyright Dino Morelli 2013-2015  All rights reserved. 
+ README.md view
@@ -0,0 +1,24 @@+# hscrtmpl+++## Synopsis++Haskell shell script template (Haskell)+++## Description++A template for writing shell scripts in Haskell. Contains some+useful functions and examples of things commonly done in bash.+++## Getting source++- Download the cabalized source package [from Hackage](http://hackage.haskell.org/package/hscrtmpl)+- Get the source with darcs: `$ darcs get http://hub.darcs.net/dino/hscrtmpl`+- If you're just looking, [browse the source](http://hub.darcs.net/dino/hscrtmpl)+++## Contact++Dino Morelli <[dino@ui3.info](mailto:dino@ui3.info)>
+ TODO.md view
+ changelog.md view
@@ -0,0 +1,28 @@+1.3 (2015-07-03)++   * Most of the commented examples are now live code+   * Replaced deprecated System.Cmd with System.Process+   * Updated copyright date+   * Fixed ambiguous import of defaultTimeLocale+   * Fixed some things in the cabal file+   * Added README.md file+++1.2 (2014-02-28)++   * Updated cabal fields+   * Updated copyright date+   * Now using a shorter date format string+   * Updated date/time code for System.Time deprecation+++1.1 (2013-09-13)++   * Added a Setup.hs to make this a valid cabalized package+   * Added new utility functions toExitCode, exitBool and forSystem+   * Added custom boringfile+  ++1.0 (2013-04-15)++   * Initial release
hscrtmpl.cabal view
@@ -1,29 +1,34 @@ name:                hscrtmpl-version:             1.2+version:             1.3 cabal-version:       >= 1.8 build-type:          Simple license:             BSD3 license-file:        LICENSE-copyright:           2013-2014 Dino Morelli+copyright:           2013-2015 Dino Morelli author:              Dino Morelli maintainer:          Dino Morelli <dino@ui3.info> stability:           experimental-homepage:            http://ui3.info/darcs/hscrtmpl/+homepage:            http://hub.darcs.net/dino/hscrtmpl synopsis:            Haskell shell script template description:         A template for writing shell scripts in Haskell. Contains some useful functions and examples of things commonly done in bash. category:            Application, Console, Scripting-tested-with:         GHC >= 7.6.3+tested-with:         GHC >= 7.10.1 +extra-source-files:  changelog.md+                     README.md+                     TODO.md+                     util/prefs/boring+ source-repository    head    type:             darcs-   location:         http://ui3.info/darcs/hscrtmpl+   location:         http://hub.darcs.net/dino/hscrtmpl  -- Hey! hscrtmpl.hs is a *script*, you don't have to build it unless -- you want to have a binary! executable           hscrtmpl    main-is:          hscrtmpl.hs-   build-depends:    base >= 3 && < 5,-                     directory,-                     old-locale,-                     process,-                     time+   build-depends:      base >= 3 && < 5+                     , directory+                     , process+                     , regex-compat+                     , time
hscrtmpl.hs view
@@ -9,46 +9,86 @@    The idea here is to take a copy of this script and hack it to do    what you need quickly. Throw the rest out. -   The script starts off (after the imports) with some simple examples-   in main.+   The script starts off (after the imports) with a main full of+   examples of common things along with their bash counterparts.     After that are a few functions that simplify things like getting    the date as a String, logging a date-stamped String to stdout and    manupulating an ExitCode as a true/false value. -   Finally, there is a comment block full of examples in bash and some-   Haskell code to do something along the same lines.     Dino Morelli <dino@ui3.info>-   http://ui3.info/d/proj/hscrtmpl.html-   version: 1.2+   http://hub.darcs.net/dino/hscrtmpl+   version: 1.3 -} ---import Control.Monad ( when, unless )+import Control.Monad import Data.Time-import System.Cmd import System.Directory---import System.Environment+import System.Environment import System.Exit-import System.Locale---import System.Process+import System.Process import Text.Printf---import Text.Regex+import Text.Regex   main :: IO () main = do-   printf "This is a shell script\n"+   putStrLn "This is a shell script" -   putStrLn =<< date+                                             -- in bash:+   -- dates (Date.Time)+   putStrLn =<< date                         -- date+   putStrLn =<< dateFormat "%Y%m%d"          -- date +"%Y%m%d"+      -- These two functions below -   home <- getHomeDirectory-   let prompt = printf "HOME is %s" home-   putStrLn prompt+   -- file/dir things (System.Directory)+   putStrLn =<< getHomeDirectory             -- echo $HOME+   print =<< doesFileExist "foo"             -- [ -f foo ]+   print =<< doesDirectoryExist "bar"        -- [ -d bar ]+   putStrLn =<< getCurrentDirectory          -- pwd+   --setCurrentDirectory "/tmp"                -- cd /tmp +   -- conditional statements (Control.Monad)+   e <- doesFileExist "hscrtmpl.hs"          -- [ -f hscrtmpl.hs ]+   when e $ putStrLn "This script exists!"   --    && echo "This script exists!"+   ++   -- environment variables (System.Environment)+   putStrLn =<< getEnv "SHELL"               -- echo $SHELL++   -- arguments (System.Environment)+   --(args1 : args2 : _) <- getArgs            -- arg1=$1 ; arg2=$2++   -- string interpolation (Text.Printf)+   printf "The %s is %d\n"                   -- S="answer" ; D=42+      "answer" (42::Int)                     -- echo "The $S is $D"++   -- execution, exit code (System.Process)+   ec <- system "ls -l"                      -- ls -l+   print ec                                  -- echo $?++   -- execution, capture stdout (System.Process)+   output <- readProcess "ls" ["-l"]         -- output=$(ls -l)+      "stdin data, if desired"++      -- or use readProcessWithExitCode+      -- :: FilePath -> [String] -> String -> IO (ExitCode, String, String)+      --    program     args        stdin         exitcode  stdout  stderr++   -- regular expressions (Text.Regex)+   print $ matchRegex                        -- (see bash docs for =~+      (mkRegex "a(.)b(.)") "axby"            --  and BASH_REMATCH)++   -- Handy date-stamping logM function below    logM "Example of a log message" +   -- exiting (System.Exit)+   exitSuccess                               -- exit 0+   --exitFailure                             -- exit 1+   --exitWith $ ExitFailure 3                -- exit 3 + {- Get the current date/time as a string in RFC822 format    Looks like this in my locale: Mon Feb 13 16:21:38 EST 2012 -}@@ -103,57 +143,3 @@    return $ case all (== ExitSuccess) ecs of       True  -> ExitSuccess       False -> ExitFailure 1---{- Some common bash things and their Haskell counterparts:--   bash                             Haskell-   ----                             --------   dates                            System.Locale, System.Time-      date                             date--      date +"%Y%m%d"                   dateFormat "%Y%m%d"-         result: 20120213-                                    (these two functions above)--   file/dir things                  System.Directory-      $HOME                            getHomeDirectory-      [ -f FILE ]                      doesFileExist FILE-      [ -d DIR ]                       doesDirectoryExist DIR-      pwd                              getCurrentDirectory-      cd DIR                           setCurrentDirectory DIR--   environment variables            System.Environment-      $VAR                             getEnv "VAR"--   arguments                        System.Environment-      arg1=$1                          (arg1 : arg2 : _) <- getArgs-      arg2=$2--   string interpolation             Text.Printf-      "foo $bar ${baz}"                printf "foo %s %d" bar baz--   execution, exit code             System.Cmd-      program -x val arg               ec <- system "program -x val arg"-      ec=$?--   execution, capture stdout        System.Process-      output=$(program -x val arg)     output <- readProcess "program"-                                          ["-x", "val", "arg"]-                                          "stdin data, if desired"--      or use System.Process.readProcessWithExitCode-      :: FilePath -> [String] -> String -> IO (ExitCode, String, String)-         program     args        stdin         exitcode  stdout  stderr--   exiting                          System.Exit-      exit 0                           exitSuccess-      exit 1                           exitFailure-      exit INT                         exitWith $ ExitFailure INT--   regular expressions              Text.Regex-      (see bash docs for =~            mbMatches = matchRegex-       and BASH_REMATCH)                  (mkRegex "a(.)b(.)") string-                                          :: Maybe [String]---}
+ util/prefs/boring view
@@ -0,0 +1,120 @@+# This file contains a list of extended regular expressions, one per+# line. A file path matching any of these expressions will be filtered+# out during `darcs add', or when the `--look-for-adds' flag is passed+# to `darcs whatsnew' and `record'.  The entries in ~/.darcs/boring (if+# it exists) supplement those in this file.+# +# Blank lines, and lines beginning with an octothorpe (#) are ignored.+# See regex(7) for a description of extended regular expressions.++### compiler and interpreter intermediate files+# haskell (ghc) interfaces+\.hi$+\.hi-boot$+\.o-boot$+# object files+\.o$+\.o\.cmd$+# profiling haskell+\.p_hi$+\.p_o$+# haskell program coverage resp. profiling info+\.tix$+\.prof$+# fortran module files+\.mod$+# linux kernel+\.ko\.cmd$+\.mod\.c$+(^|/)\.tmp_versions($|/)+# *.ko files aren't boring by default because they might+# be Korean translations rather than kernel modules+# \.ko$+# python, emacs, java byte code+\.py[co]$+\.elc$+\.class$+# objects and libraries; lo and la are libtool things+\.(obj|a|exe|so|lo|la)$+# compiled zsh configuration files+\.zwc$+# Common LISP output files for CLISP and CMUCL+\.(fas|fasl|sparcf|x86f)$++### build and packaging systems+# cabal intermediates+\.installed-pkg-config+\.setup-config+# standard cabal build dir, might not be boring for everybody+^dist(/|$)+# autotools+(^|/)autom4te\.cache($|/)+(^|/)config\.(log|status)$+# microsoft web expression, visual studio metadata directories+\_vti_cnf$+\_vti_pvt$+# gentoo tools+\.revdep-rebuild.*+# generated dependencies+^\.depend$++### version control systems+# cvs+(^|/)CVS($|/)+\.cvsignore$+# cvs, emacs locks+^\.#+# rcs+(^|/)RCS($|/)+,v$+# subversion+(^|/)\.svn($|/)+# mercurial+(^|/)\.hg($|/)+# git+(^|/)\.git($|/)+# bzr+\.bzr$+# sccs+(^|/)SCCS($|/)+# darcs+(^|/)_darcs($|/)+(^|/)\.darcsrepo($|/)+^\.darcs-temp-mail$+-darcs-backup[[:digit:]]+$+# gnu arch+(^|/)(\+|,)+(^|/)vssver\.scc$+\.swp$+(^|/)MT($|/)+(^|/)\{arch\}($|/)+(^|/).arch-ids($|/)+# bitkeeper+(^|/)BitKeeper($|/)+(^|/)ChangeSet($|/)++### miscellaneous+# backup files+~$+\.bak$+\.BAK$+# patch originals and rejects+\.orig$+\.rej$+# X server+\..serverauth.*+# image spam+\#+(^|/)Thumbs\.db$+# vi, emacs tags+(^|/)(tags|TAGS)$+#(^|/)\.[^/]+# core dumps+(^|/|\.)core$+# partial broken files (KIO copy operations)+\.part$+# waf files, see http://code.google.com/p/waf/+(^|/)\.waf-[[:digit:].]+-[[:digit:]]+($|/)+(^|/)\.lock-wscript$+# mac os finder+(^|/)\.DS_Store$