Commit | Line | Data |
---|---|---|
a78e1140 | 1 | #!/data/data/com.termux/files/usr/bin/bash |
0ec2b704 | 2 | set -e -u |
59f0d218 | 3 | |
0ec2b704 | 4 | SCRIPTNAME=termux-notification |
59f0d218 | 5 | show_usage () { |
a78e1140 FF |
6 | echo "Usage: termux-notification [options]" |
7 | echo "Display a system notification. Context text is read from stdin or specified using --content." | |
8 | echo " --action action action to execute when pressing the notification" | |
9 | echo " --button1 text text to show on the first notification button" | |
10 | echo " --button1-action action action to execute on the first notification button" | |
11 | echo " --button2 text text to show on the second notification button" | |
12 | echo " --button2-action action action to execute on the second notification button" | |
13 | echo " --button3 text text to show on the third notification button" | |
14 | echo " --button3-action action action to execute on the third notification button" | |
15 | echo " --content content contnet to show in the notification. Read from stdin not specified here." | |
16 | echo " --id id notification id (will overwrite any previous notification with the same id)" | |
17 | echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)" | |
18 | echo " --led-on milliseconds number of milliseconds for the LED to be on while it's flashing (default: 800)" | |
19 | echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)" | |
20 | echo " --priority prio notification priority (high/low/max/min/default)" | |
21 | echo " --sound play a sound with the notification" | |
22 | echo " --title title notification title to show" | |
23 | echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200" | |
bea93fbd | 24 | exit 0 |
59f0d218 FF |
25 | } |
26 | ||
a78e1140 | 27 | OPT_ACTION="" |
b4443d5e | 28 | OPT_ID="" |
b4443d5e | 29 | OPT_LED_COLOR="" |
b4443d5e | 30 | OPT_LED_OFF="" |
a78e1140 FF |
31 | OPT_LED_ON="" |
32 | OPT_PRIORITY="" | |
b4443d5e | 33 | OPT_SOUND="" |
a78e1140 FF |
34 | OPT_TITLE="" |
35 | OPT_VIBRATE="" | |
36 | OPT_BUTTON1_TEXT="" | |
37 | OPT_BUTTON1_ACTION="" | |
38 | OPT_BUTTON2_TEXT="" | |
39 | OPT_BUTTON2_ACTION="" | |
40 | OPT_BUTTON3_TEXT="" | |
41 | OPT_BUTTON3_ACTION="" | |
0ec2b704 | 42 | |
b4443d5e FF |
43 | TEMP=`busybox getopt \ |
44 | -n $SCRIPTNAME \ | |
a78e1140 FF |
45 | -o hc:i:t: \ |
46 | --long action:,\ | |
47 | button1:,button1-action:,\ | |
48 | button2:,button2-action:,\ | |
49 | button3:,button3-action:,\ | |
50 | content:,help,id:,\ | |
51 | led-color:,led-on:,led-off:,\ | |
52 | priority:,sound,title:,vibrate: \ | |
b4443d5e FF |
53 | -s bash \ |
54 | -- "$@"` | |
55 | eval set -- "$TEMP" | |
56 | ||
57 | while true; do | |
58 | case "$1" in | |
a78e1140 FF |
59 | --action) OPT_ACTION="$2"; shift 2;; |
60 | --button1) OPT_BUTTON1_TEXT="$2"; shift 2;; | |
61 | --button1-action) OPT_BUTTON1_ACTION="$2"; shift 2;; | |
62 | --button2) OPT_BUTTON2_TEXT="$2"; shift 2;; | |
63 | --button2-action) OPT_BUTTON2_ACTION="$2"; shift 2;; | |
64 | --button3) OPT_BUTTON3_TEXT="$2"; shift 2;; | |
65 | --button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;; | |
66 | -c | --content) OPT_CONTENT="$2"; shift 2;; | |
b4443d5e FF |
67 | -h | --help) show_usage;; |
68 | -i | --id) OPT_ID="$2"; shift 2;; | |
69 | --led-color) OPT_LED_COLOR="$2"; shift 2;; | |
70 | --led-on) OPT_LED_ON="$2"; shift 2;; | |
71 | --led-off) OPT_LED_OFF="$2"; shift 2;; | |
72 | --priority) OPT_PRIORITY="$2"; shift 2;; | |
73 | --sound) OPT_SOUND="true"; shift 1;; | |
a78e1140 | 74 | -t | --title) OPT_TITLE="$2"; shift 2;; |
b4443d5e FF |
75 | --vibrate) OPT_VIBRATE="$2"; shift 2;; |
76 | --) shift; break ;; | |
0ec2b704 | 77 | esac |
59f0d218 | 78 | done |
0ec2b704 FF |
79 | |
80 | if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi | |
59f0d218 | 81 | |
8d6e165f | 82 | set -- |
a78e1140 FF |
83 | if [ -n "$OPT_ACTION" ]; then set -- "$@" --es action "$OPT_ACTION"; fi |
84 | if [ -n "$OPT_BUTTON1_ACTION" ]; then set -- "$@" --es button_action_1 "$OPT_BUTTON1_ACTION"; fi | |
85 | if [ -n "$OPT_BUTTON1_TEXT" ]; then set -- "$@" --es button_text_1 "$OPT_BUTTON1_TEXT"; fi | |
86 | if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUTTON2_ACTION"; fi | |
87 | if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi | |
88 | if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi | |
89 | if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi | |
b4443d5e | 90 | if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi |
b4443d5e | 91 | if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi |
b4443d5e | 92 | if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi |
a78e1140 | 93 | if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi |
b4443d5e FF |
94 | if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi |
95 | if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi | |
a78e1140 | 96 | if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi |
b4443d5e | 97 | if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi |
8d6e165f | 98 | |
85699cc8 FF |
99 | if [ -v OPT_CONTENT ]; then |
100 | # Note that we want to accept an empty content (--content ""). | |
101 | echo ${OPT_CONTENT:=""} | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@" | |
a78e1140 FF |
102 | else |
103 | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@" | |
104 | fi |