Skip to content

Instantly share code, notes, and snippets.

@missinglink
Last active December 30, 2015 08:08
Show Gist options
  • Select an option

  • Save missinglink/7800267 to your computer and use it in GitHub Desktop.

Select an option

Save missinglink/7800267 to your computer and use it in GitHub Desktop.
Functional programming with bash experiment.
#!/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
}
@sevko
Copy link
Copy Markdown

sevko commented Jun 10, 2015

what have you done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment