Created
October 7, 2014 10:15
-
-
Save oldratlee/6b00937de6193c99b3ba to your computer and use it in GitHub Desktop.
colorful-lines
This file contains hidden or 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 | |
colorEcho() { | |
local color="$1" | |
shift | |
if [ -c /dev/stdout ] ; then | |
# if stdout is console, turn on color output. | |
echo -ne "\033[1;${color}m" | |
echo -n "$@" | |
echo -e "\033[0m" | |
else | |
echo "$@" | |
fi | |
} | |
[ $# -eq 0 ] && files=(/dev/stdin) || files=("$@") | |
readonly ECHO_COLORS=(37 31 32 34 33 35 56) | |
COUNT=0 | |
for file in "${files[@]}"; do | |
[ ${#files[@]} -gt 1 ] && { | |
echo "==== $file ====" | |
} | |
while read line; do | |
colorEcho "${ECHO_COLORS[$((COUNT++ % ${#ECHO_COLORS[@]}))]}" "$line" | |
done < "$file" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add to https://github.com/oldratlee/useful-scripts#beer-colorful-lines