Skip to content

Instantly share code, notes, and snippets.

@sigma
Created April 8, 2012 19:27
Show Gist options
  • Save sigma/2339459 to your computer and use it in GitHub Desktop.
Save sigma/2339459 to your computer and use it in GitHub Desktop.
tee_exec.sh
#!/bin/zsh
tempdir=$(mktemp -d) || exit
in_pipe="$tempdir/in_pipe"
out_pipe="$tempdir/out_pipe"
pipe="$1"
shift
function cleanUp() {
rm -rf -- "$tempdir"
rm -f -- "$pipe"
}
mkfifo $in_pipe
mkfifo $out_pipe
mkfifo $pipe
trap "cleanUp" EXIT
cat $in_pipe | (while read line; do echo "[IN] $line"; done) > $pipe &
cat $out_pipe | (while read line; do echo "[OUT] $line"; done) > $pipe &
tee -a $in_pipe | $* | tee -a $out_pipe
cleanUp
trap - EXIT
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment