Skip to content

Instantly share code, notes, and snippets.

@alexsancho
Created December 14, 2011 22:13
Show Gist options
  • Select an option

  • Save alexsancho/1478807 to your computer and use it in GitHub Desktop.

Select an option

Save alexsancho/1478807 to your computer and use it in GitHub Desktop.
Display a message.
#!/usr/bin/env bash
#####################################################################
# Program: log
#####################################################################
# Version: 1.0
# Date: 18.10.2011
# Author: (c) by Alex Sancho - <alex@alexsancho.name>
#
# Notes: Display a message.
#####################################################################
function usage()
{
prname=$(basename $0)
log "$prname: Display a message."
log "Usage: $prname [-s] [-e] [-w] [-n] [-g] [-t] <string>"
log "Examp: $prname -w \"this is a warning!!\""
log "Options:"
log " $prname [-s] displays a success message"
log " $prname -e displays an error message"
log " $prname -w displays a warning message"
log " $prname -n displays a warning message using -n as an echo argument"
log " $prname -g displays a message using growlnotify"
log " $prname -t sets the title of growl alert"
}
function _main_()
{
local response="" newline="" growl="" title=""
[[ -n 1 ]] || return 0;
if [[ $# -eq 1 ]]; then
response="\033[00;37m$1\033[00m"
fi
while getopts ":s:e:w:g:t:nh[-help]:" optname
do
case "$optname" in
h | -help)
usage
exit 0
;;
s)
response="\033[00;32m$OPTARG\033[00m"
;;
e)
response="\033[00;31m$OPTARG\033[00m"
;;
w)
response="\033[0;35m$OPTARG\033[00m"
;;
n)
newline=n
;;
t)
title="$OPTARG"
;;
g)
growl=1
response="$OPTARG"
;;
\?)
$0 -w "Invalid option: -$OPTARG" >&2
;;
:)
$0 -e "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if [[ $growl && $(which growlnotify) ]]; then
growlnotify "$title" --appIcon "Terminal" --message "$response"
else
echo -e$newline $response
fi
return 0
}
## Run script...
_main_ "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment