Created
December 20, 2013 06:52
-
-
Save jhs/8051291 to your computer and use it in GitHub Desktop.
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
# Pop up a message using notify-send or growlnotify. Example: n git push | |
popup() { | |
if [ -z "$notifier" ]; then | |
if which 'notify-send' >/dev/null 2>/dev/null; then | |
notifier='notify-send' | |
elif which growlnotify >/dev/null 2>/dev/null; then | |
notifier="growlnotify" | |
else | |
echo "popup error: cannot find notify-send or growlnotify" >&2 | |
return 1 | |
fi | |
fi | |
n_images=$(dirname "$BASH_SOURCE") | |
if [ -d "$n_images/../files/img" ]; then | |
n_images="$n_images/../files/img" | |
else | |
n_images="$n_images/img" | |
fi | |
notify="$notifier" | |
if [ "$notifier-$1" = "growlnotify-Success" ]; then | |
shift | |
notify="$notifier --image=$n_images/ok.png Success --message" | |
elif [ "$notifier-$1" = "growlnotify-Fail" ]; then | |
shift | |
notify="$notifier --image=$n_images/window_close.png Fail --message" | |
fi | |
$notify "$*" | |
unset notify | |
unset n_images | |
} | |
# Returns result with notify-send. | |
n() | |
{ | |
"$@" ; n_result=$? | |
if [ "$n_result" = 0 ]; then | |
popup "Success" "$*" | |
else | |
popup "Fail" "$*" | |
fi | |
return "$n_result" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment