Last active
December 30, 2015 08:08
-
-
Save missinglink/7800267 to your computer and use it in GitHub Desktop.
Functional programming with bash experiment.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment