aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThien-Thi Nguyen <ttn@gnuvola.org>2022-04-24 09:52:47 -0400
committerThien-Thi Nguyen <ttn@gnuvola.org>2022-04-24 09:52:47 -0400
commit6ece5330af02170401c2477fb89ea7208bd6ae83 (patch)
treecd399925c39f03e984be75680d58b1c1ed519080
parent197aa2f9664635f798297681f60477f79d1b30b7 (diff)
downloadgana-6ece5330af02170401c.tar.gz
gana-6ece5330af02170401c.zip
add support for optional arg SELEXP
* format.sh (version): Bump to "1.3". (selexp): Set to $2, if given. <top-level>: Bifurcate on whether or not SELEXP is specified. If specified, filter through ‘recsel -e SELEXP’ first. Otherwise, run recfmt straight away, as before.
-rwxr-xr-xformat.sh23
1 files changed, 20 insertions, 3 deletions
diff --git a/format.sh b/format.sh
index 3ddf115..4e041e3 100755
--- a/format.sh
+++ b/format.sh
@@ -1,13 +1,19 @@
1#!/bin/sh 1#!/bin/sh
2## 2##
3# Usage: format.sh TEMPLATE 3# Usage: format.sh TEMPLATE [SELEXP]
4# 4#
5# This runs recfmt w/ template file TEMPLATE, taking input from stdin, 5# This runs recfmt w/ template file TEMPLATE, taking input from stdin,
6# and writing output to stdout. 6# and writing output to stdout.
7#
8# Optional arg SELEXP is an expression passed to ‘recsel -e’. If specified,
9# stdin is first processed by recsel and its output is then piped to recfmt
10# for formatting. If recsel exits failurefully (e.g., given invalid SELEXP),
11# no output is written and format.sh exits failurefully as well.
7## 12##
8me=$(basename $0) 13me=$(basename $0)
9 14
10version='1.2' 15version='1.3'
16# 1.3 -- add support for optional arg SELEXP
11# 1.2 -- add check for required arg TEMPLATE 17# 1.2 -- add check for required arg TEMPLATE
12# 1.1 -- add --help/--version support 18# 1.1 -- add --help/--version support
13# 1.0 -- initial release 19# 1.0 -- initial release
@@ -29,6 +35,17 @@ fi
29 35
30template="$1" 36template="$1"
31 37
32exec recfmt -f "$template" 38if [ x"$2" = x ] ; then : ; else
39 selexp="$2"
40fi
41
42if [ "$selexp" ] ; then
43 t=$(mktemp -p .)
44 trap "rm -f $t" EXIT
45 recsel -e "$selexp" > $t &&
46 recfmt -f "$template" < $t
47else
48 exec recfmt -f "$template"
49fi
33 50
34# format.sh ends here 51# format.sh ends here