Skip to content

Instantly share code, notes, and snippets.

@oldratlee
Created October 7, 2014 10:15
Show Gist options
  • Save oldratlee/6b00937de6193c99b3ba to your computer and use it in GitHub Desktop.
Save oldratlee/6b00937de6193c99b3ba to your computer and use it in GitHub Desktop.
colorful-lines
#!/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
@oldratlee
Copy link
Author

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