Skip to content
Snippets Groups Projects
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
Branches
No related tags found
No related merge requests found
...@@ -144,14 +144,7 @@ alias nextcloudcmd='flatpak run --command=nextcloudcmd org.nextcloud.Nextcloud' ...@@ -144,14 +144,7 @@ alias nextcloudcmd='flatpak run --command=nextcloudcmd org.nextcloud.Nextcloud'
alias tfa='terraform apply tfplan' alias tfa='terraform apply tfplan'
alias tfvf='tfv && terraform fmt -diff' alias tfvf='tfv && terraform fmt -diff'
if ! command -v notify-send > /dev/null alias notify="notify --hint \"string:desktop-entry:$(basename "${GIO_LAUNCHED_DESKTOP_FILE:-io.elementary.terminal.desktop}")\""
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
tfp () { tfp () {
workspace="$(terraform workspace show)" workspace="$(terraform workspace show)"
...@@ -372,9 +365,9 @@ __command_notifier () { ...@@ -372,9 +365,9 @@ __command_notifier () {
then then
if [ "$exitstatus" -eq '0' ] if [ "$exitstatus" -eq '0' ]
then then
notify-send "$last_command has finished." echo "$last_command has finished." | notify
else else
notify-send --urgency=critical "$last_command has failed." echo "$last_command has failed." | notify --urgency=critical
fi fi
fi fi
fi fi
......
#!/bin/sh #!/bin/sh
set -eu set -eu
if ! command -v notify-send > /dev/null if [ "$(whoami)" = "root" ] && [ -n "${SUDO_USER:-}" ]
then then
notify="printf '\\a'" notify="sudo --preserve-env --set-home --user $SUDO_USER notify"
elif [ "$(whoami)" = "root" ] && [ -n "${SUDO_USER:-}" ]
then
notify="sudo --preserve-env --set-home --user $SUDO_USER notify-send"
else else
notify='notify-send' notify='notify'
fi fi
eval "$@" || code="$?" eval "$@" || code="$?"
...@@ -16,9 +13,9 @@ code="${code:-0}" ...@@ -16,9 +13,9 @@ code="${code:-0}"
if [ "$code" -eq 0 ] if [ "$code" -eq 0 ]
then then
$notify "$(basename "${1#__}") has finished." echo "$(basename "${1#__}") has finished." | $notify
else else
$notify --urgency=critical "$(basename "${1#__}") has failed." echo "$(basename "${1#__}") has failed." | $notify --urgency=critical
fi fi
return "$code" return "$code"
#!/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
...@@ -11,10 +11,9 @@ do ...@@ -11,10 +11,9 @@ do
then then
message="$(echo "$message" | sed 's/message=//; s/+/ /g')" message="$(echo "$message" | sed 's/message=//; s/+/ /g')"
fi fi
notify-send \ echo "$message" | notify \
--urgency low \ --urgency low \
--hint "string:desktop-entry:spammer" \ --hint "string:desktop-entry:spammer"
"$message"
# Backoff in case of an error. # Backoff in case of an error.
if [ "$exitstatus" -gt '0' ] if [ "$exitstatus" -gt '0' ]
then then
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment