aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-05-10 23:20:51 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-05-10 23:24:04 +1200
commit13a4187ab7cf193d626c6a9ce6f4f87fe2ef837f (patch)
treecd1ef0df4ee05d746515ed98006a858cfb2da04f
parentUpdate submodules (diff)
downloaddotfiles-13a4187ab7cf193d626c6a9ce6f4f87fe2ef837f.tar.gz
dotfiles-13a4187ab7cf193d626c6a9ce6f4f87fe2ef837f.zip
Add pst(1df), ped(1df), and pvi(1df)
-rw-r--r--.gitignore3
-rw-r--r--Makefile3
-rw-r--r--README.markdown5
-rw-r--r--[-rwxr-xr-x]bin/clog.sh0
-rw-r--r--[-rwxr-xr-x]bin/gred.sh0
-rw-r--r--bin/ped.sh2
-rw-r--r--bin/pst.sh32
-rw-r--r--bin/pvi.sh2
-rw-r--r--man/man1/ped.1df19
-rw-r--r--man/man1/pst.1df25
-rw-r--r--man/man1/pvi.1df19
11 files changed, 110 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index ea3ec93a..bafd0f1e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,10 +63,13 @@ bin/onl
bin/osc
bin/pa
bin/paz
+bin/ped
bin/pit
bin/plmu
bin/pp
bin/pph
+bin/pst
+bin/pvi
bin/pwg
bin/quo
bin/rfcf
diff --git a/Makefile b/Makefile
index 9d987150..999b90ac 100644
--- a/Makefile
+++ b/Makefile
@@ -139,10 +139,13 @@ BINS = bin/ap \
bin/osc \
bin/pa \
bin/paz \
+ bin/ped \
bin/pit \
bin/plmu \
bin/pp \
bin/pph \
+ bin/pst \
+ bin/pvi \
bin/pwg \
bin/quo \
bin/rfcf \
diff --git a/README.markdown b/README.markdown
index 0d71ed12..3afc6900 100644
--- a/README.markdown
+++ b/README.markdown
@@ -448,6 +448,11 @@ Installed by the `install-bin` target:
* Two time duration functions:
* `hms(1df)` converts seconds to `hh:mm:ss` or `mm:ss` timestamps.
* `sec(1df)` converts `hh:mm:ss` or `mm:ss` timestamps to seconds.
+* Three pipe interaction tools:
+ * `pst(1df)` runs an interactive program on data before passing it along
+ a pipeline.
+ * `ped(1df)` runs `pst(1df)` with `$EDITOR` or `ed(1)`.
+ * `pvi(1df)` runs `pvi(1df)` with `$VISUAL` or `vi(1)`.
* `ap(1df)` reads arguments for a given command from the standard input,
prompting if appropriate.
* `apf(1df)` prepends arguments to a command with ones read from a file,
diff --git a/bin/clog.sh b/bin/clog.sh
index b17ff1c5..b17ff1c5 100755..100644
--- a/bin/clog.sh
+++ b/bin/clog.sh
diff --git a/bin/gred.sh b/bin/gred.sh
index 46de5dce..46de5dce 100755..100644
--- a/bin/gred.sh
+++ b/bin/gred.sh
diff --git a/bin/ped.sh b/bin/ped.sh
new file mode 100644
index 00000000..ba2f7e66
--- /dev/null
+++ b/bin/ped.sh
@@ -0,0 +1,2 @@
+# Use pst(1df) to edit a pipe partway through, like vipe(1)
+pst "${EDITOR:-ed}"
diff --git a/bin/pst.sh b/bin/pst.sh
new file mode 100644
index 00000000..fdea9884
--- /dev/null
+++ b/bin/pst.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Interrupt a pipe with manual /dev/tty input to a program
+self=pst
+
+# Don't accept terminal as stdin
+if [ -t 0 ] ; then
+ printf >&2 '%s: stdin is a term\n' "$self"
+ exit 2
+fi
+
+# 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"
+ if [ "$1" != EXIT ] ; then
+ trap - "$1"
+ kill "-$1" "$$"
+ fi
+}
+for sig in EXIT HUP INT TERM ; do
+ # shellcheck disable=SC2064
+ trap "cleanup $sig" "$sig"
+done
+td=$(mktd "$self") || exit
+
+# Run the interactive command on the temporary file forcing /dev/tty as
+# input/output
+tf=$td/data
+cat - > "$tf" || exit
+"${@:-"${PAGER:-more}"}" "$tf" </dev/tty >/dev/tty
+cat -- "$tf" || exit
diff --git a/bin/pvi.sh b/bin/pvi.sh
new file mode 100644
index 00000000..85fc5671
--- /dev/null
+++ b/bin/pvi.sh
@@ -0,0 +1,2 @@
+# Use pst(1df) to edit a pipe partway through, like vipe(1)
+pst "${VISUAL:-vi}"
diff --git a/man/man1/ped.1df b/man/man1/ped.1df
new file mode 100644
index 00000000..fba85943
--- /dev/null
+++ b/man/man1/ped.1df
@@ -0,0 +1,19 @@
+.TH PED 1df "May 2017" "Manual page for ped"
+.SH NAME
+.B ped
+\- stop a pipe for $EDITOR intervention
+.SH SYNOPSIS
+prog1 |
+.B
+ped
+| prog2
+.SH DESCRIPTION
+.B ped
+saves all its standard input into a temporary file and runs $EDITOR, or ed(1)
+if unset, on that file. Once the editor exits, it emits the contents of the
+same file (changed or unchanged). This can be used as a way to edit data
+manually as it goes through a pipe.
+.SH SEE ALSO
+pst(1df), pvi(1df)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/pst.1df b/man/man1/pst.1df
new file mode 100644
index 00000000..cf3ce281
--- /dev/null
+++ b/man/man1/pst.1df
@@ -0,0 +1,25 @@
+.TH PST 1df "May 2017" "Manual page for pst"
+.SH NAME
+.B pst
+\- stop a pipe for manual viewing or intervention
+.SH SYNOPSIS
+prog1 |
+.B
+pst
+| prog2
+.br
+prog1 |
+.B
+pst ed
+| prog2
+.SH DESCRIPTION
+.B pst
+saves all its standard input into a temporary file and runs the interactive
+command given, defaulting to a suitable pager, and then emits the contents of
+the same file (changed or unchanged) after the program exits. This can be used
+as a way to watch the progress of data as it goes through the pipe, or to
+manually edit it.
+.SH SEE ALSO
+ped(1df), pvi(1df)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/pvi.1df b/man/man1/pvi.1df
new file mode 100644
index 00000000..990ea589
--- /dev/null
+++ b/man/man1/pvi.1df
@@ -0,0 +1,19 @@
+.TH PED 1df "May 2017" "Manual page for pvi"
+.SH NAME
+.B pvi
+\- stop a pipe for $EDITOR intervention
+.SH SYNOPSIS
+prog1 |
+.B
+pvi
+| prog2
+.SH DESCRIPTION
+.B pvi
+saves all its standard input into a temporary file and runs $VISUAL, or vi(1)
+if unset, on that file. Once the editor exits, it emits the contents of the
+same file (changed or unchanged). This can be used as a way to edit data
+manually as it goes through a pipe.
+.SH SEE ALSO
+pst(1df), ped(1df)
+.SH AUTHOR
+Tom Ryder <tom@sanctum.geek.nz>