Skip to content

Instantly share code, notes, and snippets.

@benfairless
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfairless/6f3606658e35ac101b66 to your computer and use it in GitHub Desktop.
Save benfairless/6f3606658e35ac101b66 to your computer and use it in GitHub Desktop.
Pretty bash output
# 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