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 FF |
27 | OPT_ACTION="" |
28 | OPT_CONTENT="" | |
b4443d5e | 29 | OPT_ID="" |
b4443d5e | 30 | OPT_LED_COLOR="" |
b4443d5e | 31 | OPT_LED_OFF="" |
a78e1140 FF |
32 | OPT_LED_ON="" |
33 | OPT_PRIORITY="" | |
b4443d5e | 34 | OPT_SOUND="" |
a78e1140 FF |
35 | OPT_TITLE="" |
36 | OPT_VIBRATE="" | |
37 | OPT_BUTTON1_TEXT="" | |
38 | OPT_BUTTON1_ACTION="" | |
39 | OPT_BUTTON2_TEXT="" | |
40 | OPT_BUTTON2_ACTION="" | |
41 | OPT_BUTTON3_TEXT="" | |
42 | OPT_BUTTON3_ACTION="" | |
0ec2b704 | 43 | |
b4443d5e FF |
44 | TEMP=`busybox getopt \ |
45 | -n $SCRIPTNAME \ | |
a78e1140 FF |
46 | -o hc:i:t: \ |
47 | --long action:,\ | |
48 | button1:,button1-action:,\ | |
49 | button2:,button2-action:,\ | |
50 | button3:,button3-action:,\ | |
51 | content:,help,id:,\ | |
52 | led-color:,led-on:,led-off:,\ | |
53 | priority:,sound,title:,vibrate: \ | |
b4443d5e FF |
54 | -s bash \ |
55 | -- "$@"` | |
56 | eval set -- "$TEMP" | |
57 | ||
58 | while true; do | |
59 | case "$1" in | |
a78e1140 FF |
60 | --action) OPT_ACTION="$2"; shift 2;; |
61 | --button1) OPT_BUTTON1_TEXT="$2"; shift 2;; | |
62 | --button1-action) OPT_BUTTON1_ACTION="$2"; shift 2;; | |
63 | --button2) OPT_BUTTON2_TEXT="$2"; shift 2;; | |
64 | --button2-action) OPT_BUTTON2_ACTION="$2"; shift 2;; | |
65 | --button3) OPT_BUTTON3_TEXT="$2"; shift 2;; | |
66 | --button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;; | |
67 | -c | --content) OPT_CONTENT="$2"; shift 2;; | |
b4443d5e FF |
68 | -h | --help) show_usage;; |
69 | -i | --id) OPT_ID="$2"; shift 2;; | |
70 | --led-color) OPT_LED_COLOR="$2"; shift 2;; | |
71 | --led-on) OPT_LED_ON="$2"; shift 2;; | |
72 | --led-off) OPT_LED_OFF="$2"; shift 2;; | |
73 | --priority) OPT_PRIORITY="$2"; shift 2;; | |
74 | --sound) OPT_SOUND="true"; shift 1;; | |
a78e1140 | 75 | -t | --title) OPT_TITLE="$2"; shift 2;; |
b4443d5e FF |
76 | --vibrate) OPT_VIBRATE="$2"; shift 2;; |
77 | --) shift; break ;; | |
0ec2b704 | 78 | esac |
59f0d218 | 79 | done |
0ec2b704 FF |
80 | |
81 | if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi | |
59f0d218 | 82 | |
8d6e165f | 83 | set -- |
a78e1140 FF |
84 | if [ -n "$OPT_ACTION" ]; then set -- "$@" --es action "$OPT_ACTION"; fi |
85 | if [ -n "$OPT_BUTTON1_ACTION" ]; then set -- "$@" --es button_action_1 "$OPT_BUTTON1_ACTION"; fi | |
86 | if [ -n "$OPT_BUTTON1_TEXT" ]; then set -- "$@" --es button_text_1 "$OPT_BUTTON1_TEXT"; fi | |
87 | if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUTTON2_ACTION"; fi | |
88 | if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi | |
89 | if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi | |
90 | if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi | |
b4443d5e | 91 | if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi |
b4443d5e | 92 | if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi |
b4443d5e | 93 | if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi |
a78e1140 | 94 | if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi |
b4443d5e FF |
95 | if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi |
96 | if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi | |
a78e1140 | 97 | if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi |
b4443d5e | 98 | if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi |
8d6e165f | 99 | |
a78e1140 FF |
100 | if [ -n "$OPT_CONTENT" ]; then |
101 | echo $OPT_CONTENT | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@" | |
102 | else | |
103 | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@" | |
104 | fi |