From 3df562d552a880471e8951fda030ba051d641b14 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Wed, 16 Feb 2022 23:49:16 -0500 Subject: [PATCH] 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! --- bin/demo | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/bin/demo b/bin/demo index 7849657..2986946 100755 --- 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 </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" -- libgit2 1.1.1