aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.markdown3
-rwxr-xr-xbin/edda61
-rw-r--r--man/edda.119
3 files changed, 83 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index ab87294f..195c95c1 100644
--- a/README.markdown
+++ b/README.markdown
@@ -285,6 +285,9 @@ Three SSH-related scripts and their manuals are included:
If you want to use the manuals, you may need to add `~/.local/share/man` to
your `/etc/manpath` configuration, depending on your system.
+`edda(1)` provides a means to run `ed(1)` over a set of files preserving any
+options, mostly useful for scripts. There’s `--help` output and a manual page.
+
There's also a script `han(1)` to provide a `keywordprg` for Bash script
development that will look for `help` topics. You could use it from the shell
too. It also has a brief manual.
diff --git a/bin/edda b/bin/edda
new file mode 100755
index 00000000..154fb415
--- /dev/null
+++ b/bin/edda
@@ -0,0 +1,61 @@
+#!/usr/bin/env bash
+
+#
+# edda(1) -- Run ed(1) over multiple files, duplicating stdin. Example:
+#
+# $ edda /etc/app.d/*.conf <<EOF
+# ,s/foo/bar/g
+# w
+# EOF
+#
+# Author: Tom Ryder <tom@sanctum.geek.nz>
+# Copyright: 2015
+# License: Public domain
+#
+
+# Name self
+self=edda
+
+# Define usage function
+usage() {
+ printf 'USAGE: %s [OPTS] [--] FILE1 [FILE2...]\n' "$self"
+}
+
+# Parse options out, give help if necessary
+declare -a opts
+for arg ; do
+ case $arg in
+ --help|-h|-\?)
+ usage
+ exit
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ shift
+ opts=("${opts[@]}" "$arg")
+ ;;
+ esac
+done
+
+# Duplicate stdin into a file, which we'll remove on exit
+stdin=$(mktemp) || exit
+cleanup() {
+ rm -f "$stdin"
+}
+trap cleanup EXIT
+cat > "$stdin"
+
+# Need at least one file
+if ! (($#)) ; then
+ usage >&2
+ exit 1
+fi
+
+# Run ed(1) over each file with the options and stdin given
+for file ; do
+ ed "${opts[@]}" "$file" < "$stdin"
+done
+
diff --git a/man/edda.1 b/man/edda.1
new file mode 100644
index 00000000..24c93fe9
--- /dev/null
+++ b/man/edda.1
@@ -0,0 +1,19 @@
+.TH EDDA 1 "June 2015" "Manual page for edda"
+.SH NAME
+.B edda
+\- run ed(1) over multiple files
+.SH SYNOPSIS
+.B ed [OPTS] [--] 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:
+.P
+ $ edda /etc/app.d/*.conf <<EOF
+ ,s/foo/bar/g
+ w
+ EOF
+.SH SEE ALSO
+ed(1)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
+