fixed reverse patch (#620)
[termux-packages] / packages / termux-api / termux-notification
CommitLineData
b4443d5e 1#!/bin/bash
0ec2b704 2set -e -u
59f0d218 3
0ec2b704 4SCRIPTNAME=termux-notification
59f0d218 5show_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
23CONTENT_OR_TITLE_SET=no
24ARG_C=""
25OPT_C=""
b4443d5e 26OPT_ID=""
0ec2b704
FF
27ARG_T=""
28OPT_T=""
29ARG_U=""
30OPT_U=""
b4443d5e
FF
31OPT_PRIORITY=""
32OPT_LED_COLOR=""
33OPT_LED_ON=""
34OPT_LED_OFF=""
35OPT_VIBRATE=""
36OPT_SOUND=""
0ec2b704 37
b4443d5e
FF
38TEMP=`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 -- "$@"`
44eval set -- "$TEMP"
45
46while 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 61done
0ec2b704
FF
62
63if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
59f0d218
FF
64
65if [ $CONTENT_OR_TITLE_SET = "no" ]; then
0ec2b704
FF
66 echo "$SCRIPTNAME: no title or content set"
67 exit 1
68fi
59f0d218 69
8d6e165f
FF
70set --
71if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi
b4443d5e 72if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi
8d6e165f
FF
73if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
74if [ -n "$ARG_U" ]; then set -- "$@" $ARG_U "$OPT_U"; fi
b4443d5e
FF
75if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi
76if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi
77if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi
78if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi
79if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi
80if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi
8d6e165f
FF
81
82@TERMUX_API@ Notification "$@"