diff options
author | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-04-24 09:52:47 -0400 |
---|---|---|
committer | Thien-Thi Nguyen <ttn@gnuvola.org> | 2022-04-24 09:52:47 -0400 |
commit | 6ece5330af02170401c2477fb89ea7208bd6ae83 (patch) | |
tree | cd399925c39f03e984be75680d58b1c1ed519080 /format.sh | |
parent | 197aa2f9664635f798297681f60477f79d1b30b7 (diff) | |
download | gana-6ece5330af02170401c2477fb89ea7208bd6ae83.tar.gz gana-6ece5330af02170401c2477fb89ea7208bd6ae83.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.
Diffstat (limited to 'format.sh')
-rwxr-xr-x | format.sh | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -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 | ## |
8 | me=$(basename $0) | 13 | me=$(basename $0) |
9 | 14 | ||
10 | version='1.2' | 15 | version='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 | ||
30 | template="$1" | 36 | template="$1" |
31 | 37 | ||
32 | exec recfmt -f "$template" | 38 | if [ x"$2" = x ] ; then : ; else |
39 | selexp="$2" | ||
40 | fi | ||
41 | |||
42 | if [ "$selexp" ] ; then | ||
43 | t=$(mktemp -p .) | ||
44 | trap "rm -f $t" EXIT | ||
45 | recsel -e "$selexp" > $t && | ||
46 | recfmt -f "$template" < $t | ||
47 | else | ||
48 | exec recfmt -f "$template" | ||
49 | fi | ||
33 | 50 | ||
34 | # format.sh ends here | 51 | # format.sh ends here |