Commit e3966f76 authored by nimrod's avatar nimrod
Browse files

Another notification improvement.

- A wrapper for different notification mechanisms, for different hosts.
- Implement it where needed.
parent 561661cd
Loading
Loading
Loading
Loading
+3 −10
Original line number Diff line number Diff line
@@ -144,14 +144,7 @@ alias nextcloudcmd='flatpak run --command=nextcloudcmd org.nextcloud.Nextcloud'
alias tfa='terraform apply tfplan'
alias tfvf='tfv && terraform fmt -diff'

if ! command -v notify-send > /dev/null
then
    alias notify-send='bell'
elif [ -n "$GIO_LAUNCHED_DESKTOP_FILE" ]
then
    # shellcheck disable=SC2139
    alias notify-send="notify-send --hint \"string:desktop-entry:$(basename "$GIO_LAUNCHED_DESKTOP_FILE")\""
fi
alias notify="notify --hint \"string:desktop-entry:$(basename "${GIO_LAUNCHED_DESKTOP_FILE:-io.elementary.terminal.desktop}")\""

tfp () {
    workspace="$(terraform workspace show)"
@@ -372,9 +365,9 @@ __command_notifier () {
        then
            if [ "$exitstatus" -eq '0' ]
            then
                notify-send "$last_command has finished."
                echo "$last_command has finished." | notify
            else
                notify-send --urgency=critical "$last_command has failed."
                echo "$last_command has failed." | notify --urgency=critical
            fi
        fi
    fi
+5 −8
Original line number Diff line number Diff line
#!/bin/sh
set -eu

if ! command -v notify-send > /dev/null
if [ "$(whoami)" = "root" ] && [ -n "${SUDO_USER:-}" ]
then
    notify="printf '\\a'"
elif [ "$(whoami)" = "root" ] && [ -n "${SUDO_USER:-}" ]
then
    notify="sudo --preserve-env --set-home --user $SUDO_USER notify-send"
    notify="sudo --preserve-env --set-home --user $SUDO_USER notify"
else
    notify='notify-send'
    notify='notify'
fi

eval "$@" || code="$?"
@@ -16,9 +13,9 @@ code="${code:-0}"

if [ "$code" -eq 0 ]
then
    $notify "$(basename "${1#__}") has finished."
    echo "$(basename "${1#__}") has finished." | $notify
else
    $notify --urgency=critical "$(basename "${1#__}") has failed."
    echo "$(basename "${1#__}") has failed." | $notify --urgency=critical
fi

return "$code"

Documents/bin/notify

0 → 100755
+46 −0
Original line number Diff line number Diff line
#!/bin/sh
set -eu

bell () {
    printf '\\a'
}

wall () {
    $(command -v wall) "$(id -g)"
}

notify_send () {
    message="$(cat)"
    $(command -v notify-send) "$@" "$message"
}

patchbay () {
    message="$(cat)"
    curl -d "$message" https://patchbay.pub/pubsub/1446c969-9a54-4b5b-83e0-bf88f22f289d
}

# Try hostname if present.
if command -v hostname > /dev/null
then
    hostname="$(hostname)"
# Try using sysfs (Linux only).
elif [ -f /proc/sys/kernel/hostname ]
then
    hostname="$(cat /proc/sys/kernel/hostname)"
# Fallback to grepping sysctl.
else
    hostname="$(sysctl -a 2>/dev/null | awk -F '=' '/^kern[a-z]*\.hostname/ {print $2}')"
fi

#FIXME: Remove domain, just hostname.

case "$hostname" in
    ea6350) patchbay;;
    host01) patchbay;;
    kodi) patchbay;;
    ns1) patchbay;;
    ns4) patchbay;;
    workbench) patchbay;;
    YOGA-C930) notify_send "$@";;
    *) ;;
esac
+2 −3
Original line number Diff line number Diff line
@@ -11,10 +11,9 @@ do
    then
        message="$(echo "$message" | sed 's/message=//; s/+/ /g')"
    fi
    notify-send \
    echo "$message" | notify \
        --urgency low \
        --hint "string:desktop-entry:spammer" \
        "$message"
        --hint "string:desktop-entry:spammer"
    # Backoff in case of an error.
    if [ "$exitstatus" -gt '0' ]
    then