Add libnotify notification if found

If `send-notify` is recognized as valid command, the dbg_msg function
will send it there instead of printing it to stdout. The urgency of the
message corresponds with low/normal/critical to the debug levels
info/warn/error.
This commit is contained in:
Marty Oehme 2020-02-16 09:58:58 +01:00
parent 467cea919c
commit 27f0988a5e
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A

View file

@ -78,7 +78,24 @@ dbg_msg() {
info) display=2 ;; info) display=2 ;;
esac esac
# if the user wants to be informed, send it out there
if (("$level" <= "$display")); then if (("$level" <= "$display")); then
printf "%b%-15s %s \u001b[0m\n" "$color" "$(tr '[:lower:]' '[:upper:]' <<<\["$application"])" "$@"
# send it to notification daemon if libnotify exists
if command -v notify-send >/dev/null; then
local urgency
case "$level" in
0) urgency="critical" ;;
1) urgency="normal" ;;
2 | *) urgency="low" ;;
esac
notify-send --urgency="$urgency" "$(tr '[:lower:]' '[:upper:]' <<<\["$application"])" "$@"
else
# otherwise just print it out
printf "%s: 📦 %s must be installed for this function.\n" "$2" "$1"
printf "%b%-15s %s \u001b[0m\n" "$color" "$(tr '[:lower:]' '[:upper:]' <<<\["$application"])" "$@"
fi
fi fi
} }