commit 3df562d552a880471e8951fda030ba051d641b14 (patch)
parent a7b864876dbb070f3e55121ba33fc549242ee8be
Author: Alex Karle <alex@alexkarle.com>
Date: Wed, 16 Feb 2022 23:49:16 -0500
bin: Update demo(1) to save to a named file
I realized that the xclip(1) support was really not very handy.
In practice, I often make typing errors and use backspace, arrow keys,
etc. Copying these to the clipboard just results in sharing garbage.
Instead, I need to `cat` the file and copy the scrollback (easy using
tmux(1)).
To make sure it persists even if the terminal fails, demo(1) now saves
to $HOME/demo with a file name based on ARGV!
Diffstat:
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/bin/demo b/bin/demo
@@ -1,5 +1,19 @@
#!/bin/sh
# demo -- script(1) wrapper with shell config for better copy/pasta
+set -e
+die() {
+ echo "$*" 1>&2
+ exit 1
+}
+
+[ -z "$1" ] && die "usage: demo 'brief description'"
+
+desc=$(printf "$*" | tr '[[:space:]]' '_')
+OUT=$HOME/demo/$desc.script
+if [ -e "$OUT" ]; then
+ die "ERROR: demo file $OUT already exists"
+fi
+
cat <<EOM >/tmp/demo.env
export TERM=dumb
export PAGER=cat
@@ -7,10 +21,6 @@ alias g="echo 'Use the full command during demo(1)!'"
PS1='\$ '
EOM
+mkdir -p "$HOME/demo"
export ENV=/tmp/demo.env
-script -c /bin/sh /tmp/demo.out
-
-if command -v xclip >/dev/null; then
- sed -e '1d' -e '/^\$ ^D/d' -e '$d' /tmp/demo.out | tr -d '\r' | xclip
- echo "Demo output copied to middle-mouse clipboard!"
-fi
+script -c /bin/sh "$OUT"