Skip to content

Instantly share code, notes, and snippets.

@ChrisPenner
Created April 5, 2020 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisPenner/6074895b51de797ebcbcb1c21cc2b12b to your computer and use it in GitHub Desktop.
Save ChrisPenner/6074895b51de797ebcbcb1c21cc2b12b to your computer and use it in GitHub Desktop.
Capture can replay command line output
#!/bin/bash
capdir=/tmp/cap
mkdir -p "$capdir"
record() {
tee "${capdir}/${1:-default}"
}
replay() {
cat "${capdir}/${1:-default}"
}
case $1 in
rec*)
shift; record "$1"
;;
rep*) shift; replay "$1"
;;
*) cat >&2 <<EOF
Usage:
Capture output:
cmd | cap record [capture name]
Output previous capture:
cap replay [capture name] | use output
EOF
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment