X-Git-Url: https://git.distorted.org.uk/~mdw/misc/blobdiff_plain/412abc9e49c747cb032b099e7a6a6e4622682891..8b628e9f2ad95491f8a5f5354fc4101c07b80514:/buf diff --git a/buf b/buf index c95cf89..1bb1958 100755 --- a/buf +++ b/buf @@ -1,18 +1,27 @@ #! /bin/sh set -e -case "$#:$1" in - 0:* | 1:-h | 1:--help) - echo "Usage: $0 PROG ARGS..." - echo " Buffer stdin to temp file and pass to PROG with ARGS" - exit 0 - ;; -esac +ext="" +while :; do + case "$#:$1" in + 0:* | *:-h | *:--help) + echo "Usage: $0 [-e EXT] PROG ARGS..." + echo " Buffer stdin to temp file and pass to PROG with ARGS" + exit 0 + ;; + 1:-e) echo >&2 "$0: missing argument"; exit 1 ;; + *:-e) ext=$2; shift 2 ;; + *:-e*) ext=${1#-e}; shift ;; + *:--) shift; break ;; + *:-*) echo >&2 "$0: unknown option \`$1'"; exit 1 ;; + *) break ;; + esac +done tmp=${TMPDIR-/tmp}/buf-$$ mkdir "$tmp" trap 'rm -rf "$tmp"' INT QUIT TERM HUP EXIT -cat >"$tmp/buf" -set +e; "$@" "$tmp/buf"; st=$?; set -e +cat >"$tmp/buf$ext" +set +e; "$@" "$tmp/buf$ext"; st=$?; set -e trap '' INT QUIT TERM HUP EXIT rm -rf "$tmp" exit $st