Skip to content

Instantly share code, notes, and snippets.

@jonlabelle
Last active July 12, 2022 15:48
Show Gist options
  • Save jonlabelle/7093921 to your computer and use it in GitHub Desktop.
Save jonlabelle/7093921 to your computer and use it in GitHub Desktop.
Bash functions to output colorized messages in the terminal, according to context.
# show a cyan `OK!`, or arg `1` message
function show_info()
{
local msg="OK!"
if [ ! -z "$1" ]; then
msg="$1"
fi
echo -e "\033[0;36m${msg}\033[0m"
}
# show a magneta `OK!`, or arg `1` message
function show_info_alt()
{
local msg="OK!"
if [ ! -z "$1" ]; then
msg="$1"
fi
echo -e "\033[0;35m${msg}\033[0m"
}
# show a green `Success!`, or arg `1` message
function show_success()
{
local msg="Success!"
if [ ! -z "$1" ]; then
msg="$1"
fi
echo -e "\033[0;32m${msg}\033[0m"
}
# show a yellow `Warning!`, or arg `1` message
function show_warning()
{
local msg="Warning!"
if [ ! -z "$1" ]; then
msg="$1"
fi
echo -e "\033[0;33m${msg}\033[0m"
}
# show a red `Error!`, or arg `1` message
function show_error()
{
local msg="Error!"
if [ ! -z "$1" ]; then
msg="$1"
fi
echo -e "\033[0;31m${msg}\033[0m"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment