#!/bin/bash _arg_t=2 fname=$(basename "$0") usage () { echo "$fname [options] [command] Sends notification when the given command finished executing Options: -h Show this message then exit -t Time the notification stays. By default 2 -T Notification title -m <string> Displays this message when finished. Variable resolution on > Default message is '<command> finished'" } warning () { if [ ! -n "$_opt_w" ] ; then printf "\033[0;33m$1\033[0m\n" >&2 fi } error () { printf "\033[1;31m$1\033[0m\n" >&2 } _args="" # $1 = message , $2 = time , $3 = title notify () { if which kdialog >/dev/null then kdialog --passivepopup "$1" $2 --title "$3" elif which notify-send >/dev/null then notify-send -t $2 "$3" "$1" else echo "No supported notification" >&2 && return 1 fi } # read options while getopts ":hm:T:t:" opt; do case $opt in h) usage exit 0 ;; m) if [ ! -n "$OPTARG" ] then error "m needs an argument" exit fi message=$OPTARG _opt_m=y ;; T) title="$OPTARG" ;; t) _arg_t="$OPTARG" ;; \?) echo "Uknown option: $OPTARG" usage exit 1 ;; esac done shift $((OPTIND-1)) if [ $# -gt 0 ] then [ ! -n "$_opt_m" ] && message="'$*' finished" [ -z "$title" ] && title=$* $@ else [ ! -n "$_opt_m" ] && message="Ping" [ -z "$title" ] && title="Ping" fi notify "$message" $_arg_t "$title"