-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify.sh
36 lines (32 loc) · 1.16 KB
/
notify.sh
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
#!/usr/bin/env bash
#=== FUNCTION ================================================================
# NAME: notify
# DESCRIPTION: Calls notify-send with some addational logic and defaults
# PARAMETERS: [ -t <topic> ] [ -t <timeout in seconds> ] [ -i <icon> ]
#===============================================================================
notify() {
local timeout=30
local topic='Notify'
local icon='info'
while [[ ${1} =~ ^-[ti]$ ]]; do
if [[ ${1} == '-t' && ${2} =~ ^[0-9]+$ ]]; then
timeout=${2}
elif [[ ${1} == '-t' ]]; then
topic=${2}
elif [[ ${1} == '-i' ]]; then
icon=${2}
fi
shift;shift;
done
timeout=$((timeout * 1000))
notify-send -i "${icon}" -t "${timeout}" "${topic}" " ${*}"
} # end of function notify
#-------------------------------------------------------------------------------
# Example usage
#-------------------------------------------------------------------------------
#
# notify test
# notify -t test the topic is test
# notify -t 10 message with a 10 second timeout
# notify -t 10 -t test a 10 second timeout and topic test
# notify -t 10 -i error -t test an error icon and a 10 second timeout and topic test