Commit | Line | Data |
---|---|---|
b4443d5e | 1 | #!/bin/bash |
0ec2b704 | 2 | set -e -u |
59f0d218 | 3 | |
0ec2b704 | 4 | SCRIPTNAME=termux-notification |
59f0d218 | 5 | show_usage () { |
bea93fbd FF |
6 | echo "Usage: termux-notification [-c content] [-i id] [-t title] [-u url]" |
7 | echo "Display a system notification." | |
8 | echo "" | |
b4443d5e FF |
9 | echo " -c,--content content notification content to show" |
10 | echo " -i id notification id (will overwrite any previous notification with the same id)" | |
11 | echo " --led-color color of the blinking led as RRGGBB (default: none)" | |
12 | echo " --led-on number of milliseconds for the LED to be on while it's flashing (default: 800)" | |
13 | echo " --led-off number of milliseconds for the LED to be off while it's flashing (default: 800)" | |
14 | echo " --priority notification priority (high/low/max/min/default)" | |
15 | echo " --sound play a sound with the notification" | |
16 | echo " -t,--title title notification title to show" | |
17 | echo " -u url notification url when clicking on it" | |
18 | echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200" | |
bea93fbd FF |
19 | echo "" |
20 | exit 0 | |
59f0d218 FF |
21 | } |
22 | ||
0ec2b704 FF |
23 | CONTENT_OR_TITLE_SET=no |
24 | ARG_C="" | |
25 | OPT_C="" | |
b4443d5e | 26 | OPT_ID="" |
0ec2b704 FF |
27 | ARG_T="" |
28 | OPT_T="" | |
29 | ARG_U="" | |
30 | OPT_U="" | |
b4443d5e FF |
31 | OPT_PRIORITY="" |
32 | OPT_LED_COLOR="" | |
33 | OPT_LED_ON="" | |
34 | OPT_LED_OFF="" | |
35 | OPT_VIBRATE="" | |
36 | OPT_SOUND="" | |
0ec2b704 | 37 | |
b4443d5e FF |
38 | TEMP=`busybox getopt \ |
39 | -n $SCRIPTNAME \ | |
40 | -o hc:i:t:u: \ | |
41 | --long content:,help,id:,led-color:,led-on:,led-off:,priority:,sound,vibrate: \ | |
42 | -s bash \ | |
43 | -- "$@"` | |
44 | eval set -- "$TEMP" | |
45 | ||
46 | while true; do | |
47 | case "$1" in | |
48 | -c | --content) ARG_C="--es content"; OPT_C="$2"; CONTENT_OR_TITLE_SET=yes; shift 2;; | |
49 | -h | --help) show_usage;; | |
50 | -i | --id) OPT_ID="$2"; shift 2;; | |
51 | --led-color) OPT_LED_COLOR="$2"; shift 2;; | |
52 | --led-on) OPT_LED_ON="$2"; shift 2;; | |
53 | --led-off) OPT_LED_OFF="$2"; shift 2;; | |
54 | --priority) OPT_PRIORITY="$2"; shift 2;; | |
55 | --sound) OPT_SOUND="true"; shift 1;; | |
56 | -t | --title) ARG_T="--es title"; OPT_T="$2"; CONTENT_OR_TITLE_SET=yes; shift 2;; | |
57 | -u) ARG_U="--es url"; OPT_U="$2"; shift 2;; | |
58 | --vibrate) OPT_VIBRATE="$2"; shift 2;; | |
59 | --) shift; break ;; | |
0ec2b704 | 60 | esac |
59f0d218 | 61 | done |
0ec2b704 FF |
62 | |
63 | if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi | |
59f0d218 FF |
64 | |
65 | if [ $CONTENT_OR_TITLE_SET = "no" ]; then | |
0ec2b704 FF |
66 | echo "$SCRIPTNAME: no title or content set" |
67 | exit 1 | |
68 | fi | |
59f0d218 | 69 | |
8d6e165f FF |
70 | set -- |
71 | if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi | |
b4443d5e | 72 | if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi |
8d6e165f FF |
73 | if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi |
74 | if [ -n "$ARG_U" ]; then set -- "$@" $ARG_U "$OPT_U"; fi | |
b4443d5e FF |
75 | if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi |
76 | if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi | |
77 | if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi | |
78 | if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi | |
79 | if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi | |
80 | if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi | |
8d6e165f FF |
81 | |
82 | @TERMUX_API@ Notification "$@" |