Last active
August 29, 2015 14:15
-
-
Save benfairless/6f3606658e35ac101b66 to your computer and use it in GitHub Desktop.
Pretty bash output
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
# Purely cosmetic function to prettify output | |
# Set OUTPUT_LABEL to change the label | |
# Supports ERROR, SUCCESS, and WARN as arguments | |
output() { | |
local label=${OUTPUT_LABEL:-$0} | |
local timestamp=$(date +%H:%M) | |
local colour='\033[34m' # Blue | |
local reset='\033[0m' # Standard | |
case $1 in | |
ERROR) local colour='\033[31m' ;; # Red | |
SUCCESS) local colour='\033[32m' ;; # Green | |
WARN) local colour='\033[33m' ;; # Yellow | |
esac | |
while read line; do | |
echo -e "${colour}${label} [${timestamp}]${reset} ${line}" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment