summaryrefslogtreecommitdiff
path: root/dotfiles/common/.local/bin/notify
blob: a89a3ffb3251ab751a0062e87f3cc95e1058ca4f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# notify - Display notifications with icons and sounds
#
# Usage:
#   notify <type> "title" "body" [--persist]
#
# Types:
#   success  - Green checkmark, pleasant chime
#   fail     - Red X, warning tone
#   alert    - Yellow exclamation, attention tone
#   question - Blue question mark, contemplative tone
#   alarm    - Alarm clock icon, alarm sound
#   info     - Blue info icon, confident tone
#   security - Shield icon, security tone
#   bug      - Bug icon, error tone
#
# Options:
#   --persist  Don't auto-dismiss (stays until manually closed)
#
# Examples:
#   notify success "Job Complete" "Download finished in 12 minutes"
#   notify fail "Job Failed" "Connection refused" --persist
#   notify alert "Warning" "Network speed reduced"
#   notify question "Input Needed" "Continue or abort?"

set -euo pipefail

ICON_DIR="$HOME/.local/share/icons/notify"
SOUND_DIR="$HOME/.local/share/sounds/notify"

usage() {
    cat <<EOF
Usage: notify <type> "title" "body" [--persist]

Types:
  success   Green checkmark, pleasant chime
  fail      Red X, warning tone
  alert     Yellow exclamation, attention tone
  question  Blue question mark, contemplative tone
  alarm     Alarm clock, alarm sound
  info      Blue info icon, confident tone
  security  Shield icon, security tone
  bug       Bug icon, error tone

Options:
  --persist  Don't auto-dismiss notification

Examples:
  notify success "Job Complete" "Download finished"
  notify fail "Build Failed" "Test errors" --persist
EOF
    exit 1
}

# Require at least type, title, body
if [[ $# -lt 3 ]]; then
    usage
fi

TYPE="$1"
TITLE="$2"
BODY="$3"
PERSIST="${4:-}"

# Validate type and set icon/sound
case "$TYPE" in
    success)
        ICON="$ICON_DIR/success.png"
        SOUND="$SOUND_DIR/success.ogg"
        ;;
    fail)
        ICON="$ICON_DIR/fail.png"
        SOUND="$SOUND_DIR/fail.ogg"
        ;;
    alert)
        ICON="$ICON_DIR/alert.png"
        SOUND="$SOUND_DIR/alert.ogg"
        ;;
    question)
        ICON="$ICON_DIR/question.png"
        SOUND="$SOUND_DIR/question.ogg"
        ;;
    alarm)
        ICON="$ICON_DIR/alarm.png"
        SOUND="$SOUND_DIR/alarm.ogg"
        ;;
    info)
        ICON="$ICON_DIR/info.png"
        SOUND="$SOUND_DIR/info.ogg"
        ;;
    security)
        ICON="$ICON_DIR/security.png"
        SOUND="$SOUND_DIR/security.ogg"
        ;;
    bug)
        ICON="$ICON_DIR/bug.png"
        SOUND="$SOUND_DIR/bug.ogg"
        ;;
    *)
        echo "Error: Unknown type '$TYPE'" >&2
        echo "Valid types: success, fail, alert, question, alarm, info, security, bug" >&2
        exit 1
        ;;
esac

# Check assets exist
if [[ ! -f "$ICON" ]]; then
    echo "Warning: Icon not found: $ICON" >&2
fi

if [[ ! -f "$SOUND" ]]; then
    echo "Warning: Sound not found: $SOUND" >&2
fi

# Build notify-send arguments
NOTIFY_ARGS=(
    --app-name=""
    --urgency=normal
)

# Add persist flag if requested
if [[ "$PERSIST" == "--persist" ]]; then
    NOTIFY_ARGS+=(--expire-time=0)
fi

# Add icon if it exists
if [[ -f "$ICON" ]]; then
    NOTIFY_ARGS+=(--icon="$ICON")
fi

# Play sound in background (if it exists)
if [[ -f "$SOUND" ]]; then
    paplay "$SOUND" &
fi

# Send notification
notify-send "${NOTIFY_ARGS[@]}" "$TITLE" "$BODY"