diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-06-02 22:07:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-06-02 22:07:52 +1200 |
commit | bc1d5fb28841f6050605e93886685b3a02e7787a (patch) | |
tree | f0f02d8d4884b0864334ad774c98da87c0301379 /bin | |
parent | Correct some terms in man mi5(1df) (diff) | |
download | dotfiles-bc1d5fb28841f6050605e93886685b3a02e7787a.tar.gz dotfiles-bc1d5fb28841f6050605e93886685b3a02e7787a.zip |
Use mi5 to make templated shell scripts
Diffstat (limited to 'bin')
-rw-r--r-- | bin/chn.mi5 (renamed from bin/chn.sh) | 18 | ||||
-rw-r--r-- | bin/edda.mi5 | 21 | ||||
-rw-r--r-- | bin/edda.sh | 33 | ||||
-rw-r--r-- | bin/pst.mi5 | 19 | ||||
-rw-r--r-- | bin/pst.sh | 32 | ||||
-rw-r--r-- | bin/rndl.mi5 (renamed from bin/rndl.sh) | 18 | ||||
-rw-r--r-- | bin/swr.mi5 (renamed from bin/swr.sh) | 18 | ||||
-rw-r--r-- | bin/tlcs.mi5 (renamed from bin/tlcs.sh) | 18 | ||||
-rw-r--r-- | bin/try.mi5 (renamed from bin/try.sh) | 18 | ||||
-rw-r--r-- | bin/urlc.mi5 (renamed from bin/urlc.sh) | 18 |
10 files changed, 58 insertions, 155 deletions
diff --git a/bin/chn.sh b/bin/chn.mi5 index 9103dd07..dfc1000c 100644 --- a/bin/chn.sh +++ b/bin/chn.mi5 @@ -23,21 +23,9 @@ if [ "$c" -eq 0 ] ; then exit fi -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit +<% +include(`include/mktd.m4') +%> # Define and create input and output files if=$td/if of=$td/of diff --git a/bin/edda.mi5 b/bin/edda.mi5 new file mode 100644 index 00000000..aaf974cf --- /dev/null +++ b/bin/edda.mi5 @@ -0,0 +1,21 @@ +# Run ed(1) over multiple files, duplicating stdin. +self=edda + +# Need at least one file +if [ "$#" -eq 0 ] ; then + printf >&2 'edda: Need at least one file\n' + exit 2 +fi + +<% +include(`include/mktd.m4') +%> + +# Duplicate stdin into a file +script=$td/script +cat >"$script" || exit + +# Run ed(1) over each file with the stdin given +for file ; do + ed -- "$file" <"$script" +done diff --git a/bin/edda.sh b/bin/edda.sh deleted file mode 100644 index b1d7b27a..00000000 --- a/bin/edda.sh +++ /dev/null @@ -1,33 +0,0 @@ -# Run ed(1) over multiple files, duplicating stdin. -self=edda - -# Need at least one file -if [ "$#" -eq 0 ] ; then - printf >&2 'edda: Need at least one file\n' - exit 2 -fi - -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit - -# Duplicate stdin into a file -script=$td/script -cat >"$script" || exit - -# Run ed(1) over each file with the stdin given -for file ; do - ed -- "$file" <"$script" -done diff --git a/bin/pst.mi5 b/bin/pst.mi5 new file mode 100644 index 00000000..34ffbd8c --- /dev/null +++ b/bin/pst.mi5 @@ -0,0 +1,19 @@ +# Interrupt a pipe with manual /dev/tty input to a program +self=pst + +# Don't accept terminal as stdin +if [ -t 0 ] ; then + printf >&2 '%s: stdin is a term\n' "$self" + exit 2 +fi + +<% +include(`include/mktd.m4') +%> + +# Run the interactive command on the temporary file forcing /dev/tty as +# input/output +tf=$td/data +cat - > "$tf" || exit +"${@:-"${PAGER:-more}"}" "$tf" </dev/tty >/dev/tty +cat -- "$tf" || exit diff --git a/bin/pst.sh b/bin/pst.sh deleted file mode 100644 index fdea9884..00000000 --- a/bin/pst.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# Interrupt a pipe with manual /dev/tty input to a program -self=pst - -# Don't accept terminal as stdin -if [ -t 0 ] ; then - printf >&2 '%s: stdin is a term\n' "$self" - exit 2 -fi - -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit - -# Run the interactive command on the temporary file forcing /dev/tty as -# input/output -tf=$td/data -cat - > "$tf" || exit -"${@:-"${PAGER:-more}"}" "$tf" </dev/tty >/dev/tty -cat -- "$tf" || exit diff --git a/bin/rndl.sh b/bin/rndl.mi5 index 18bcec07..f99ccbea 100644 --- a/bin/rndl.sh +++ b/bin/rndl.mi5 @@ -7,21 +7,9 @@ self=rndl # file if we don't want to read all of the input into memory (!) if [ "$#" -eq 0 ] ; then - # Create a temporary directory with name in $td, and handle POSIX-ish traps to - # remove it when the script exits. - td= - cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi - } - for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" - done - td=$(mktd "$self") || exit +<% +include(`include/mktd.m4') +%> # We'll operate on stdin in the temp directory; write the script's stdin to # it with cat(1) diff --git a/bin/swr.sh b/bin/swr.mi5 index 5bad63ae..9b73b6d6 100644 --- a/bin/swr.sh +++ b/bin/swr.mi5 @@ -1,21 +1,9 @@ # Transparently wrap scp(1) targets to read (not write) on the command line self=swr -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit +<% +include(`include/mktd.m4') +%> # Set a flag to manage resetting the positional parameters at the start of the # loop diff --git a/bin/tlcs.sh b/bin/tlcs.mi5 index f20b160e..a3e17c82 100644 --- a/bin/tlcs.sh +++ b/bin/tlcs.mi5 @@ -67,21 +67,9 @@ if [ "$((color_count >= 8))" -eq 1 ] ; then fi fi -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit +<% +include(`include/mktd.m4') +%> # Execute the command, passing stdout and stderr to tl(1df) calls as appropriate # via named pipes diff --git a/bin/try.sh b/bin/try.mi5 index 20ccbe5f..ea39d717 100644 --- a/bin/try.sh +++ b/bin/try.mi5 @@ -25,21 +25,9 @@ if [ "$#" -eq 0 ] ; then exit 2 fi -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit +<% +include(`include/mktd.m4') +%> # Open a filehandle to the error buffer, just to save on file operations errbuff=$td/errbuff diff --git a/bin/urlc.sh b/bin/urlc.mi5 index 0e6530fa..55dac171 100644 --- a/bin/urlc.sh +++ b/bin/urlc.mi5 @@ -4,21 +4,9 @@ self=urlc # cURL request timeout tm=${URLCHECK_TIMEOUT:-8} -# Create a temporary directory with name in $td, and handle POSIX-ish traps to -# remove it when the script exits. -td= -cleanup() { - [ -n "$td" ] && rm -fr -- "$td" - if [ "$1" != EXIT ] ; then - trap - "$1" - kill "-$1" "$$" - fi -} -for sig in EXIT HUP INT TERM ; do - # shellcheck disable=SC2064 - trap "cleanup $sig" "$sig" -done -td=$(mktd "$self") || exit +<% +include(`include/mktd.m4') +%> # Create buffer files for the headers and body content, to be cleaned up on # exit |