From 27f0988a5e378f6dfe135ea558d1e4f1a059563b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sun, 16 Feb 2020 09:58:58 +0100 Subject: [PATCH] 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. --- utilities.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/utilities.sh b/utilities.sh index 905788f..60bc808 100644 --- a/utilities.sh +++ b/utilities.sh @@ -78,7 +78,24 @@ dbg_msg() { info) display=2 ;; esac + # if the user wants to be informed, send it out there 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 }