hscrtmpl 1.5 → 1.6
raw patch · 10 files changed
+171/−219 lines, 10 filesdep +filepath
Dependencies added: filepath
Files
- .gitignore +5/−0
- LICENSE +1/−1
- README.md +2/−2
- TODO.md +0/−0
- changelog.md +14/−0
- hscrtmpl.cabal +40/−33
- hscrtmpl.hs +69/−58
- package.yaml +39/−0
- stack.yaml +1/−1
- util/prefs/boring +0/−124
+ .gitignore view
@@ -0,0 +1,5 @@+# stack build artifacts+.stack-work/++# Using hpack, we don't store cabal files+*.cabal
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2013-2016, Dino Morelli <dino@ui3.info>+Copyright (c) 2013-2018, Dino Morelli <dino@ui3.info> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided
README.md view
@@ -15,9 +15,9 @@ ## 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`+- Get the source with darcs: `$ git clone https://github.com/dino-/hscrtmpl.git` - Get the source with stack: `$ stack unpack hscrtmpl`-- If you're just looking, [browse the source](http://hub.darcs.net/dino/hscrtmpl)+- If you're just looking, [browse the source](https://github.com/dino-/hscrtmpl) ## Contact
− TODO.md
changelog.md view
@@ -1,3 +1,17 @@+1.6 (2018-10-03)++ * Moved copyright date up to 2018+ * Replaced out-of-fashion `fmap` with newfangled Applicative fmap+ * Changed to two-space indenting+ * Fixed a git source repository URL that was missed+ * Added some path split and dir examples+ * Removed unused TODO.md file+ * Moved stack resolver up to 12.11+ * Added example #! for runhaskell+ * Switched to hpack+ * Removed Vim swapfiles from .gitignore++ 1.5 (2016-11-18) * Changed license from BSD3 to ISC
hscrtmpl.cabal view
@@ -1,36 +1,43 @@-name: hscrtmpl-version: 1.5-cabal-version: >= 1.8-build-type: Simple-license: ISC-license-file: LICENSE-copyright: 2013-2016 Dino Morelli-author: Dino Morelli-maintainer: Dino Morelli <dino@ui3.info>-stability: stable-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 >= 8.0.1+-- This file has been generated from package.yaml by hpack version 0.28.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 94422872b0ab311808f7510b45c6c5bb31ee6db2edcd9e2d75de1aa77c28bb29 -extra-source-files: changelog.md- README.md- stack.yaml- TODO.md- util/prefs/boring+name: hscrtmpl+version: 1.6+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+homepage: https://github.com/dino-/hscrtmpl#readme+bug-reports: https://github.com/dino-/hscrtmpl/issues+author: Dino Morelli+maintainer: dino@ui3.info+copyright: 2018 Dino Morelli+license: ISC+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10+extra-source-files:+ .gitignore+ changelog.md+ package.yaml+ README.md+ stack.yaml -source-repository head- type: darcs- location: http://hub.darcs.net/dino/hscrtmpl+source-repository head+ type: git+ location: https://github.com/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- , process- --, regex-compat- , time- --, time-locale-compat+executable hscrtmpl+ main-is: hscrtmpl.hs+ other-modules:+ Paths_hscrtmpl+ ghc-options: -fwarn-tabs -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints+ build-depends:+ base >=3 && <5+ , directory+ , filepath+ , process+ , time+ default-language: Haskell2010
hscrtmpl.hs view
@@ -1,26 +1,31 @@ #! /usr/bin/env stack {- stack runghc -} -{- This is a 'skeleton file' for writing shell scripts with Haskell+{- No stack? Use this #! instead of the two lines above:+#! /usr/bin/env runhaskell+-} - Haskell is my go-to language for anything more complicated than a- simple sequence of shell commands in a bash script. Doing list- processing and a lot of logic in bash is a grind, to me.+{-+ This is a 'skeleton file' for writing shell scripts with Haskell - The idea here is to take a copy of this script and hack it to do- what you need quickly. Throw the rest out.+ Haskell is my go-to language for anything more complicated than a simple+ sequence of shell commands in a bash script. Doing list processing and a lot+ of logic in bash is a grind, to me. - The script starts off (after the imports) with a main full of- examples of common things along with their bash counterparts.+ The idea here is to take a copy of this script and hack it to do what you+ need quickly. Throw the rest out. - 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.+ 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. - Dino Morelli <dino@ui3.info>- http://hub.darcs.net/dino/hscrtmpl- version: 1.4++ Dino Morelli <dino@ui3.info>+ https://github.com/dino-/hscrtmpl+ version: 1.6 -} import Control.Monad@@ -31,6 +36,7 @@ import System.Directory import System.Environment import System.Exit+import System.FilePath import System.Process import Text.Printf --import Text.Regex@@ -38,59 +44,64 @@ main :: IO () main = do- putStrLn "This is a shell script"+ putStrLn "This is a shell script" -- in bash:- -- dates (Date.Time)- putStrLn =<< date -- date- putStrLn =<< dateFormat "%Y%m%d" -- date +"%Y%m%d"- -- These two functions below+ -- dates (Date.Time)+ putStrLn =<< date -- date+ putStrLn =<< dateFormat "%Y%m%d" -- date +"%Y%m%d"+ -- These two functions below - -- 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+ -- 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+ print =<< makeAbsolute "some/relative/path"+ -- (System.FilePath)+ let (path, ext) = splitExtension "foo/bar.baz"+ print (path, ext) - -- conditional statements (Control.Monad)- e <- doesFileExist "hscrtmpl.hs" -- [ -f hscrtmpl.hs ]- when e $ putStrLn "This script exists!" -- && echo "This script exists!"+ -- 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+ -- environment variables (System.Environment)+ putStrLn =<< getEnv "SHELL" -- echo $SHELL - -- arguments (System.Environment)- --(arg1 : arg2 : _) <- getArgs -- arg1=$1 ; arg2=$2+ -- arguments (System.Environment)+ --(arg1 : arg2 : _) <- 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"+ -- 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, 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"+ -- 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+ -- 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)+ -- 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"+ -- 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+ -- 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@@ -104,7 +115,7 @@ For format string help, see man 3 strftime -} dateFormat :: String -> IO String-dateFormat fmt = formatTime defaultTimeLocale fmt `fmap`+dateFormat fmt = formatTime defaultTimeLocale fmt <$> (getCurrentTime >>= utcToLocalZonedTime) @@ -143,7 +154,7 @@ -} forSystem :: [String] -> IO ExitCode forSystem cs = do- ecs <- mapM system cs- return $ case all (== ExitSuccess) ecs of- True -> ExitSuccess- False -> ExitFailure 1+ ecs <- mapM system cs+ return $ case all (== ExitSuccess) ecs of+ True -> ExitSuccess+ False -> ExitFailure 1
+ package.yaml view
@@ -0,0 +1,39 @@+name: hscrtmpl+version: '1.6'+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.+license: ISC+author: Dino Morelli+maintainer: dino@ui3.info+copyright: 2018 Dino Morelli+category: Application, Console, Scripting+extra-source-files:+- changelog.md+- .gitignore+- README.md+- package.yaml+- stack.yaml++github: dino-/hscrtmpl++ghc-options:+- -fwarn-tabs+- -Wall+- -Wcompat+- -Wincomplete-record-updates+- -Wincomplete-uni-patterns+- -Wredundant-constraints++# Hey! hscrtmpl.hs is a *script*, you don't have to build it unless+# you want to have a binary!+executables:+ hscrtmpl:+ main: hscrtmpl.hs+ dependencies:+ - base >=3 && <5+ - directory+ - filepath+ - process+ # - regex-compat+ - time+ # - time-locale-compat
stack.yaml view
@@ -1,4 +1,4 @@-resolver: lts-7.9+resolver: lts-12.11 packages: - '.'
− util/prefs/boring
@@ -1,124 +0,0 @@-# 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$-# emacs saved sessions (desktops)-(^|.*/)\.emacs\.desktop(\.lock)?$--(^|/).stack-work($|/)