aboutsummaryrefslogtreecommitdiff
path: root/bin
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 /bin
parentUpdate submodules (diff)
downloaddotfiles-13a4187ab7cf193d626c6a9ce6f4f87fe2ef837f.tar.gz
dotfiles-13a4187ab7cf193d626c6a9ce6f4f87fe2ef837f.zip
Add pst(1df), ped(1df), and pvi(1df)
Diffstat (limited to 'bin')
-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
5 files changed, 36 insertions, 0 deletions
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}"