Skip to content

Instantly share code, notes, and snippets.

@ferstar
Last active June 26, 2017 03:31
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 ferstar/a88e5357399559089949ac6b74ea7c54 to your computer and use it in GitHub Desktop.
Save ferstar/a88e5357399559089949ac6b74ea7c54 to your computer and use it in GitHub Desktop.
color bash prompt with timestamp ahead
#!/bin/bash
color_msg() {
if [ $# -gt 2 ]; then
echo -e "\033[1;31mUsage: ${0} [error|-e|info|-i|warn|-w] "your message".\033[0m"
fi
now_time=$(date '+[%Y/%m/%d %H:%M:%S]')
case ${1} in
# red
error|-e )
echo -e "${now_time}\t\033[1;31m${2}\033[0m"
;;
# green
info|-i )
echo -e "${now_time}\t\033[1;32m${2}\033[0m"
;;
# yellow
warn|-w )
echo -e "${now_time}\t\033[1;33m${2}\033[0m"
;;
# normal
* )
echo -e "${now_time}\t${1}"
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment