diff --git a/.bashrc b/.bashrc index 7325628d5ea358cf9323bccecfb7069c657127a2..221fc91a4deef7ee59c9a390a986525f1a4bf369 100644 --- a/.bashrc +++ b/.bashrc @@ -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 diff --git a/Documents/bin/monitor b/Documents/bin/monitor index 5053f61d5520473839c1b842ee53c98762a41dc9..0d6944cceee2aa5aed713f16d163205ccd7a49c5 100755 --- a/Documents/bin/monitor +++ b/Documents/bin/monitor @@ -1,14 +1,11 @@ #!/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" diff --git a/Documents/bin/notify b/Documents/bin/notify new file mode 100755 index 0000000000000000000000000000000000000000..073206677efab5bd72e0e428901720efbebd166d --- /dev/null +++ b/Documents/bin/notify @@ -0,0 +1,46 @@ +#!/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 diff --git a/Documents/bin/spammer b/Documents/bin/spammer index aa55fdf83d9077b12a0808e2fb877153aa5d4090..30ed9fb5da20f4f46ce25ff4bc557648b6d1d469 100755 --- a/Documents/bin/spammer +++ b/Documents/bin/spammer @@ -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