aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-19 15:08:49 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-19 15:10:26 +1200
commit6622909eacd404d8d0ab14fc75a9d6969021cd7e (patch)
treea6110577f58773f04290c3b11495c67fce318404 /bin
parentAdd issue (diff)
downloaddotfiles-6622909eacd404d8d0ab14fc75a9d6969021cd7e.tar.gz
dotfiles-6622909eacd404d8d0ab14fc75a9d6969021cd7e.zip
Port edda(1) to POSIX sh
Losing the option-passing; could perhaps add this in again by specifically supporting POSIX-specific options for ed(1)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/edda41
1 files changed, 15 insertions, 26 deletions
diff --git a/bin/edda b/bin/edda
index 26d78b94..b06a50c8 100755
--- a/bin/edda
+++ b/bin/edda
@@ -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