[!] bgnotify: always nofity when exceeding threshold

This commit is contained in:
15cm 2018-04-09 16:21:33 -04:00
commit ea61f6892e

View file

@ -16,7 +16,7 @@ if ! (type bgnotify_formatted | grep -q 'function'); then ## allow custom functi
elapsed="$(( $3 % 60 ))s"
(( $3 >= 60 )) && elapsed="$((( $3 % 3600) / 60 ))m $elapsed"
(( $3 >= 3600 )) && elapsed="$(( $3 / 3600 ))h $elapsed"
[ $1 -eq 0 ] && bgnotify "#win (took $elapsed)" "$2" || bgnotify "#fail (took $elapsed)" "$2"
[ $1 -eq 0 ] && bgnotify "#done (took $elapsed)" "$2" || bgnotify "#fail (took $elapsed)" "$2"
}
fi
@ -32,11 +32,7 @@ currentWindowId () {
bgnotify () { ## args: (title, subtitle)
if hash terminal-notifier 2>/dev/null; then #osx
[[ "$TERM_PROGRAM" == 'iTerm.app' ]] && term_id='com.googlecode.iterm2';
[[ "$TERM_PROGRAM" == 'Apple_Terminal' ]] && term_id='com.apple.terminal';
## now call terminal-notifier, (hopefully with $term_id!)
[ -z "$term_id" ] && terminal-notifier -message "$2" -title "$1" >/dev/null ||
terminal-notifier -message "$2" -title "$1" -activate "$term_id" -sender "$term_id" >/dev/null
terminal-notifier -message "$2" -title "$1" >/dev/null ||
elif hash growlnotify 2>/dev/null; then #osx growl
growlnotify -m "$1" "$2"
elif hash notify-send 2>/dev/null; then #ubuntu gnome!
@ -62,10 +58,8 @@ bgnotify_end() {
elapsed=$(( EPOCHSECONDS - bgnotify_timestamp ))
past_threshold=$(( elapsed >= bgnotify_threshold ))
if (( bgnotify_timestamp > 0 )) && (( past_threshold )); then
if [ $(currentWindowId) != "$bgnotify_windowid" ]; then
print -n "\a"
bgnotify_formatted "$didexit" "$bgnotify_lastcmd" "$elapsed"
fi
print -n "\a"
bgnotify_formatted "$didexit" "$bgnotify_lastcmd" "$elapsed"
fi
bgnotify_timestamp=0 #reset it to 0!
}