diff options
-rw-r--r-- | ISSUES.markdown | 1 | ||||
-rwxr-xr-x | bin/edda | 41 | ||||
-rw-r--r-- | man/man1/edda.1 | 10 |
3 files changed, 20 insertions, 32 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown index becf0d66..72b87ea8 100644 --- a/ISSUES.markdown +++ b/ISSUES.markdown @@ -14,7 +14,6 @@ Known issues [tom@conan:~/.dotfiles/bin](git:master)$ grep bash * apf:#!/usr/bin/env bash - edda:#!/usr/bin/env bash eds:#!/usr/bin/env bash han:#!/usr/bin/env bash @@ -1,44 +1,33 @@ -#!/usr/bin/env bash +#!/bin/sh # Run ed(1) over multiple files, duplicating stdin. -# Give up completely if no BASH_VERSINFO (<2.0) -[ -n "$BASH_VERSINFO" ] || exit - -# Parse options out, give help if necessary -declare -a opts -for arg ; do - case $arg in - --) - shift - break - ;; - -*) - shift - opts[${#opts[@]}]=$arg - ;; - esac -done - # Need at least one file after options are parsed out -if ! (($#)) ; then +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 a trap to remove it when -# the script exits +# 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" + [ -n "$td" ] && rm -fr -- "$td" + if [ "$1" != EXIT ] ; then + trap - "$1" + kill "-$1" "$$" + fi } -trap cleanup EXIT +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 options and stdin given +# Run ed(1) over each file with the stdin given for file ; do - ed "${opts[@]}" -- "$file" <"$script" + ed -- "$file" <"$script" done diff --git a/man/man1/edda.1 b/man/man1/edda.1 index 21e6b163..3123c0ce 100644 --- a/man/man1/edda.1 +++ b/man/man1/edda.1 @@ -1,14 +1,14 @@ -.TH EDDA 1 "June 2015" "Manual page for edda" +.TH EDDA 1 "August 2016" "Manual page for edda" .SH NAME .B edda \- run ed(1) over multiple files .SH SYNOPSIS -.B edda [OPTS] [--] FILE1 [FILE2...] +.B edda FILE1 [FILE2...] .SH DESCRIPTION -Duplicate any data on stdin into a temporary file, and run ed(1) with any given -options over each of the files given as the remaining arguments. Example: +Duplicate any data on stdin into a temporary file, and run ed(1) options over +each of the files given as the remaining arguments. Example: .P - $ edda -s /etc/app.d/*.conf <<EOF + $ edda /etc/app.d/*.conf <<EOF ,s/foo/bar/g w EOF |