aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-06-02 22:07:52 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-06-02 22:07:52 +1200
commitbc1d5fb28841f6050605e93886685b3a02e7787a (patch)
treef0f02d8d4884b0864334ad774c98da87c0301379
parent78e2ead680d0f35aa1dd70de91f28932284b3664 (diff)
downloaddotfiles-bc1d5fb28841f6050605e93886685b3a02e7787a.tar.gz
dotfiles-bc1d5fb28841f6050605e93886685b3a02e7787a.zip
Use mi5 to make templated shell scripts
-rw-r--r--.gitignore21
-rw-r--r--Makefile77
-rw-r--r--bin/chn.mi5 (renamed from bin/chn.sh)18
-rw-r--r--bin/edda.mi521
-rw-r--r--bin/pst.mi519
-rw-r--r--bin/pst.sh32
-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
-rw-r--r--git/gitconfig.mi5 (renamed from git/gitconfig.m4.mi5)0
-rw-r--r--gnupg/gpg.conf.mi5 (renamed from gnupg/gpg.conf.m4.mi5)0
-rw-r--r--include/mktd.mi5 (renamed from bin/edda.sh)18
-rw-r--r--tmux/tmux.conf.mi5 (renamed from tmux/tmux.conf.m4.mi5)0
15 files changed, 130 insertions, 166 deletions
diff --git a/.gitignore b/.gitignore
index 873b60a1..153d2227 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,16 +12,20 @@ bin/cf
bin/cfr
bin/chc
bin/chn
+bin/chn.sh
+bin/chn.m4
bin/clog
bin/clrd
bin/clwr
bin/csmw
-bin/dam
bin/d2u
+bin/dam
bin/ddup
bin/dmp
bin/dub
bin/edda
+bin/edda.sh
+bin/edda.m4
bin/eds
bin/exm
bin/fgscr
@@ -46,13 +50,13 @@ bin/jfc
bin/jfcd
bin/jfp
bin/loc
-bin/mi5
bin/max
bin/maybe
bin/mean
bin/med
bin/mex
bin/mftl
+bin/mi5
bin/min
bin/mkcp
bin/mkmv
@@ -73,6 +77,8 @@ bin/plmu
bin/pp
bin/pph
bin/pst
+bin/pst.sh
+bin/pst.m4
bin/pvi
bin/pwg
bin/quo
@@ -84,6 +90,8 @@ bin/rnda
bin/rndf
bin/rndi
bin/rndl
+bin/rndl.sh
+bin/rndl.m4
bin/rnds
bin/sd2u
bin/sec
@@ -102,17 +110,25 @@ bin/su2d
bin/sue
bin/supp
bin/swr
+bin/swr.sh
+bin/swr.m4
bin/td
bin/tl
bin/tlcs
+bin/tlcs.sh
+bin/tlcs.m4
bin/tm
bin/tot
bin/trs
bin/try
+bin/try.sh
+bin/try.m4
bin/u2d
bin/umake
bin/unf
bin/urlc
+bin/urlc.sh
+bin/urlc.m4
bin/urlh
bin/urlmt
bin/uts
@@ -140,6 +156,7 @@ git/gitconfig
git/gitconfig.m4
gnupg/gpg.conf
gnupg/gpg.conf.m4
+include/mktd.m4
man/man7/dotfiles.7df
tmux/tmux.conf
tmux/tmux.conf.m4
diff --git a/Makefile b/Makefile
index 11bcf6f0..8f278325 100644
--- a/Makefile
+++ b/Makefile
@@ -64,7 +64,7 @@
lint-xinit
.SUFFIXES:
-.SUFFIXES: .awk .bash .mi5 .pl .sed .sh
+.SUFFIXES: .awk .bash .m4 .mi5 .pl .sed .sh
NAME = 'Tom Ryder'
EMAIL = tom@sanctum.geek.nz
@@ -217,15 +217,67 @@ clean distclean:
rm -f -- \
$(BINS) \
$(GAMES) \
+ bin/chn.sh \
+ bin/chn.m4 \
+ bin/edda.sh \
+ bin/edda.m4 \
+ bin/pst.sh \
+ bin/pst.m4 \
+ bin/rndl.sh \
+ bin/rndl.m4 \
+ bin/swr.sh \
+ bin/swr.m4 \
+ bin/tlcs.sh \
+ bin/tlcs.m4 \
+ bin/try.sh \
+ bin/try.m4 \
+ bin/urlc.sh \
+ bin/urlc.m4 \
git/gitconfig \
git/gitconfig.m4 \
gnupg/gpg.conf \
gnupg/gpg.conf.m4 \
+ include/mktd.m4 \
man/man8/dotfiles.7df \
tmux/tmux.conf \
tmux/tmux.conf.m4 \
urxvt/ext/select
+.awk:
+ sh bin/shb.sh awk -f < $< > $@
+ chmod +x ./$@
+
+.bash:
+ sh bin/shb.sh bash < $< > $@
+ chmod +x ./$@
+
+.pl:
+ sh bin/shb.sh perl < $< > $@
+ chmod +x ./$@
+
+.sed:
+ sh bin/shb.sh sed -f < $< > $@
+ chmod +x ./$@
+
+.sh:
+ sh bin/shb.sh sh < $< > $@
+ chmod +x ./$@
+
+.mi5.m4:
+ awk -f bin/mi5.awk < $< > $@
+
+.m4.sh:
+ m4 < $< > $@
+
+bin/chn.sh: include/mktd.m4
+bin/edda.sh: include/mktd.m4
+bin/pst.sh: include/mktd.m4
+bin/rndl.sh: include/mktd.m4
+bin/swr.sh: include/mktd.m4
+bin/tlcs.sh: include/mktd.m4
+bin/try.sh: include/mktd.m4
+bin/urlc.sh: include/mktd.m4
+
git/gitconfig: git/gitconfig.m4
m4 \
-D DF_NAME=$(NAME) \
@@ -253,29 +305,6 @@ tmux/tmux.conf: tmux/tmux.conf.m4
m4 -D DF_TMUX_BG=$(TMUX_BG) -D DF_TMUX_FG=$(TMUX_FG) \
tmux/tmux.conf.m4 > $@
-.awk:
- sh bin/shb.sh awk -f < $< > $@
- chmod +x ./$@
-
-.bash:
- sh bin/shb.sh bash < $< > $@
- chmod +x ./$@
-
-.pl:
- sh bin/shb.sh perl < $< > $@
- chmod +x ./$@
-
-.sed:
- sh bin/shb.sh sed -f < $< > $@
- chmod +x ./$@
-
-.sh:
- sh bin/shb.sh sh < $< > $@
- chmod +x ./$@
-
-.mi5:
- awk -f bin/mi5.awk < $< > $@
-
install: install-bin \
install-curl \
install-ex \
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/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
diff --git a/git/gitconfig.m4.mi5 b/git/gitconfig.mi5
index bce64d6c..bce64d6c 100644
--- a/git/gitconfig.m4.mi5
+++ b/git/gitconfig.mi5
diff --git a/gnupg/gpg.conf.m4.mi5 b/gnupg/gpg.conf.mi5
index d8f14c09..d8f14c09 100644
--- a/gnupg/gpg.conf.m4.mi5
+++ b/gnupg/gpg.conf.mi5
diff --git a/bin/edda.sh b/include/mktd.mi5
index b1d7b27a..388eb9be 100644
--- a/bin/edda.sh
+++ b/include/mktd.mi5
@@ -1,12 +1,3 @@
-# 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=
@@ -22,12 +13,3 @@ for sig in EXIT HUP INT TERM ; do
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/tmux/tmux.conf.m4.mi5 b/tmux/tmux.conf.mi5
index 76d493c1..76d493c1 100644
--- a/tmux/tmux.conf.m4.mi5
+++ b/tmux/tmux.conf.mi5