diff options
| author | Anton Bobov <anton@bobov.name> | 2025-02-07 00:11:03 +0500 |
|---|---|---|
| committer | Anton Bobov <anton@bobov.name> | 2025-02-07 00:11:03 +0500 |
| commit | 62ec471101f29a43a3605d97678aefddb838468b (patch) | |
| tree | 0d26c3cd5f6d0b3e878b0117b9e917fe6f7f85d7 | |
| parent | 460337a96914315aebeb4fc93d0767cd1e5be04a (diff) | |
Add alert script
| -rwxr-xr-x | alert | 55 |
1 files changed, 55 insertions, 0 deletions
@@ -0,0 +1,55 @@ +#!/usr/bin/env bash +## Taken from https://github.com/arl/scripts/blob/main/alert +## alert sends desktop notification +## +## Usage: alert MSG [--] [CMD] +## MSG is the notification text. +## CMD is the optional command to run before showing the notification, +## in which case alert shows an error notification if CMD failed. +## +## Options: +## -h, --help Display this message. + +usage() { + [ "$*" ] && echo "$0: $*" + sed -n '/^##/,/^$/s/^## \{0,1\}//p' "$0" + exit 2 +} 2>/dev/null + +main() { + if [ $# -lt 1 ]; then + usage + fi + MSG="${1}" + shift + + while [ $# -gt 0 ]; do + case $1 in + -h | --help) usage 2>&1 ;; + --) + shift + "$@" + RC=$? + break + ;; + -*) usage "$1: unknown option" ;; + *) break ;; + esac + done + + # List of freedesktop stock icons at: + # https://specifications.freedesktop.org/icon-naming-spec/latest + if [ -z "$RC" ]; then + ICON=dialog-information + elif [[ $RC -eq 0 ]]; then + MSG=$(echo -e "$MSG\n\n\"$*\"\n\nsuccess!") + ICON=face-cool + else + MSG=$(echo -e "$MSG\n\n\"$*\"\n\nfailure!") + ICON=face-angry + fi + + notify-send --urgency=critical --icon $ICON "${MSG}" +} + +main "$@" |
