Skip to content

Instantly share code, notes, and snippets.

@missinglink
Created December 5, 2013 14:02
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 missinglink/7805591 to your computer and use it in GitHub Desktop.
Save missinglink/7805591 to your computer and use it in GitHub Desktop.
#!/bin/bash
function stdout {
echo -e "\e[32m$@\e[0m";
}
function stderr {
echo -e "\e[31m$@\e[0m" 1>&2;
}
function stdlog {
echo "$@";
} >> /tmp/foo.log
function pipe {
if [ $# -ne 0 ]; then
multi $@;
else
while read -r; do
echo $REPLY;
done
fi
}
function multi {
while read -r; do
for i in ${@:1}; do
$i $REPLY;
done
done
}
function eval {
while read -r; do
STDIN=$REPLY;
eval $1;
done
}
function :color {
case "$1" in
'red' ) eval 'echo -e "\e[31m$STDIN\e[0m"';;
'green' ) eval 'echo -e "\e[32m$STDIN\e[0m"';;
'yellow' ) eval 'echo -e "\e[33m$STDIN\e[0m"';;
'blue' ) eval 'echo -e "\e[34m$STDIN\e[0m"';;
'purple' ) eval 'echo -e "\e[35m$STDIN\e[0m"';;
'magenta' ) eval 'echo -e "\e[36m$STDIN\e[0m"';;
'grey' ) eval 'echo -e "\e[37m$STDIN\e[0m"';;
* ) eval 'echo "$STDIN"';;
esac
}
# Create some streams
function a { echo "[ STREAM A ] $@"; }
function b { echo "[ STREAM B ] $@"; }
# Pipe all the things in to the other things
ls -la |:color 'blue' |\
eval 'echo "LAYER 1: $STDIN"' |:color 'magenta' |\
eval 'echo "LAYER 2: $STDIN"' |:color 'green' |\
pipe a b |:color 'yellow';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment