vim: Update to latest patch level
[termux-packages] / packages / termux-api / termux-notification
CommitLineData
a78e1140 1#!/data/data/com.termux/files/usr/bin/bash
0ec2b704 2set -e -u
59f0d218 3
0ec2b704 4SCRIPTNAME=termux-notification
59f0d218 5show_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
27OPT_ACTION=""
28OPT_CONTENT=""
b4443d5e 29OPT_ID=""
b4443d5e 30OPT_LED_COLOR=""
b4443d5e 31OPT_LED_OFF=""
a78e1140
FF
32OPT_LED_ON=""
33OPT_PRIORITY=""
b4443d5e 34OPT_SOUND=""
a78e1140
FF
35OPT_TITLE=""
36OPT_VIBRATE=""
37OPT_BUTTON1_TEXT=""
38OPT_BUTTON1_ACTION=""
39OPT_BUTTON2_TEXT=""
40OPT_BUTTON2_ACTION=""
41OPT_BUTTON3_TEXT=""
42OPT_BUTTON3_ACTION=""
0ec2b704 43
b4443d5e
FF
44TEMP=`busybox getopt \
45 -n $SCRIPTNAME \
a78e1140
FF
46 -o hc:i:t: \
47 --long action:,\
48button1:,button1-action:,\
49button2:,button2-action:,\
50button3:,button3-action:,\
51content:,help,id:,\
52led-color:,led-on:,led-off:,\
53priority:,sound,title:,vibrate: \
b4443d5e
FF
54 -s bash \
55 -- "$@"`
56eval set -- "$TEMP"
57
58while 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 79done
0ec2b704
FF
80
81if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
59f0d218 82
8d6e165f 83set --
a78e1140
FF
84if [ -n "$OPT_ACTION" ]; then set -- "$@" --es action "$OPT_ACTION"; fi
85if [ -n "$OPT_BUTTON1_ACTION" ]; then set -- "$@" --es button_action_1 "$OPT_BUTTON1_ACTION"; fi
86if [ -n "$OPT_BUTTON1_TEXT" ]; then set -- "$@" --es button_text_1 "$OPT_BUTTON1_TEXT"; fi
87if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUTTON2_ACTION"; fi
88if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi
89if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi
90if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi
b4443d5e 91if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi
b4443d5e 92if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi
b4443d5e 93if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi
a78e1140 94if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi
b4443d5e
FF
95if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi
96if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi
a78e1140 97if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi
b4443d5e 98if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi
8d6e165f 99
a78e1140
FF
100if [ -n "$OPT_CONTENT" ]; then
101 echo $OPT_CONTENT | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
102else
103 /data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
104fi