2017-04-09 18:19:29 +02:00
|
|
|
#!/data/data/com.termux/files/usr/bin/bash
|
2018-02-12 11:24:05 +01:00
|
|
|
set -e -u -f
|
2017-04-09 18:19:29 +02:00
|
|
|
|
|
|
|
SCRIPTNAME=termux-notification
|
|
|
|
show_usage () {
|
|
|
|
echo "Usage: termux-notification [options]"
|
|
|
|
echo "Display a system notification. Context text is read from stdin or specified using --content."
|
|
|
|
echo " --action action action to execute when pressing the notification"
|
|
|
|
echo " --button1 text text to show on the first notification button"
|
|
|
|
echo " --button1-action action action to execute on the first notification button"
|
|
|
|
echo " --button2 text text to show on the second notification button"
|
|
|
|
echo " --button2-action action action to execute on the second notification button"
|
|
|
|
echo " --button3 text text to show on the third notification button"
|
|
|
|
echo " --button3-action action action to execute on the third notification button"
|
|
|
|
echo " --content content contnet to show in the notification. Read from stdin not specified here."
|
|
|
|
echo " --id id notification id (will overwrite any previous notification with the same id)"
|
|
|
|
echo " --led-color rrggbb color of the blinking led as RRGGBB (default: none)"
|
|
|
|
echo " --led-on milliseconds number of milliseconds for the LED to be on while it's flashing (default: 800)"
|
|
|
|
echo " --led-off milliseconds number of milliseconds for the LED to be off while it's flashing (default: 800)"
|
2017-04-09 19:07:53 +02:00
|
|
|
echo " --on-delete action action to execute when the the notification is cleared"
|
2017-04-09 18:19:29 +02:00
|
|
|
echo " --priority prio notification priority (high/low/max/min/default)"
|
|
|
|
echo " --sound play a sound with the notification"
|
|
|
|
echo " --title title notification title to show"
|
|
|
|
echo " --vibrate pattern vibrate pattern, comma separated as in 500,1000,200"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
OPT_ACTION=""
|
|
|
|
OPT_ID=""
|
|
|
|
OPT_LED_COLOR=""
|
|
|
|
OPT_LED_OFF=""
|
|
|
|
OPT_LED_ON=""
|
2017-04-10 08:31:38 +02:00
|
|
|
OPT_ON_DELETE_ACTION=""
|
2017-04-09 18:19:29 +02:00
|
|
|
OPT_PRIORITY=""
|
|
|
|
OPT_SOUND=""
|
|
|
|
OPT_TITLE=""
|
|
|
|
OPT_VIBRATE=""
|
|
|
|
OPT_BUTTON1_TEXT=""
|
|
|
|
OPT_BUTTON1_ACTION=""
|
|
|
|
OPT_BUTTON2_TEXT=""
|
|
|
|
OPT_BUTTON2_ACTION=""
|
|
|
|
OPT_BUTTON3_TEXT=""
|
|
|
|
OPT_BUTTON3_ACTION=""
|
|
|
|
|
|
|
|
TEMP=`busybox getopt \
|
|
|
|
-n $SCRIPTNAME \
|
|
|
|
-o hc:i:t: \
|
|
|
|
--long action:,\
|
|
|
|
button1:,button1-action:,\
|
|
|
|
button2:,button2-action:,\
|
|
|
|
button3:,button3-action:,\
|
|
|
|
content:,help,id:,\
|
|
|
|
led-color:,led-on:,led-off:,\
|
2017-04-09 19:07:53 +02:00
|
|
|
on-delete:,\
|
2017-04-09 18:19:29 +02:00
|
|
|
priority:,sound,title:,vibrate: \
|
|
|
|
-s bash \
|
|
|
|
-- "$@"`
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--action) OPT_ACTION="$2"; shift 2;;
|
|
|
|
--button1) OPT_BUTTON1_TEXT="$2"; shift 2;;
|
|
|
|
--button1-action) OPT_BUTTON1_ACTION="$2"; shift 2;;
|
|
|
|
--button2) OPT_BUTTON2_TEXT="$2"; shift 2;;
|
|
|
|
--button2-action) OPT_BUTTON2_ACTION="$2"; shift 2;;
|
|
|
|
--button3) OPT_BUTTON3_TEXT="$2"; shift 2;;
|
|
|
|
--button3-action) OPT_BUTTON3_ACTION="$2"; shift 2;;
|
|
|
|
-c | --content) OPT_CONTENT="$2"; shift 2;;
|
|
|
|
-h | --help) show_usage;;
|
|
|
|
-i | --id) OPT_ID="$2"; shift 2;;
|
|
|
|
--led-color) OPT_LED_COLOR="$2"; shift 2;;
|
|
|
|
--led-on) OPT_LED_ON="$2"; shift 2;;
|
|
|
|
--led-off) OPT_LED_OFF="$2"; shift 2;;
|
2017-04-09 19:07:53 +02:00
|
|
|
--on-delete) OPT_ON_DELETE_ACTION="$2"; shift 2;;
|
2017-04-09 18:19:29 +02:00
|
|
|
--priority) OPT_PRIORITY="$2"; shift 2;;
|
|
|
|
--sound) OPT_SOUND="true"; shift 1;;
|
|
|
|
-t | --title) OPT_TITLE="$2"; shift 2;;
|
|
|
|
--vibrate) OPT_VIBRATE="$2"; shift 2;;
|
|
|
|
--) shift; break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
|
|
|
|
|
|
|
|
set --
|
|
|
|
if [ -n "$OPT_ACTION" ]; then set -- "$@" --es action "$OPT_ACTION"; fi
|
|
|
|
if [ -n "$OPT_BUTTON1_ACTION" ]; then set -- "$@" --es button_action_1 "$OPT_BUTTON1_ACTION"; fi
|
|
|
|
if [ -n "$OPT_BUTTON1_TEXT" ]; then set -- "$@" --es button_text_1 "$OPT_BUTTON1_TEXT"; fi
|
|
|
|
if [ -n "$OPT_BUTTON2_ACTION" ]; then set -- "$@" --es button_action_2 "$OPT_BUTTON2_ACTION"; fi
|
|
|
|
if [ -n "$OPT_BUTTON2_TEXT" ]; then set -- "$@" --es button_text_2 "$OPT_BUTTON2_TEXT"; fi
|
|
|
|
if [ -n "$OPT_BUTTON3_ACTION" ]; then set -- "$@" --es button_action_3 "$OPT_BUTTON3_ACTION"; fi
|
|
|
|
if [ -n "$OPT_BUTTON3_TEXT" ]; then set -- "$@" --es button_text_3 "$OPT_BUTTON3_TEXT"; fi
|
|
|
|
if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi
|
|
|
|
if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi
|
|
|
|
if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi
|
|
|
|
if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi
|
2017-04-09 19:07:53 +02:00
|
|
|
if [ -n "$OPT_ON_DELETE_ACTION" ]; then set -- "$@" --es on_delete_action "$OPT_ON_DELETE_ACTION"; fi
|
2017-04-09 18:19:29 +02:00
|
|
|
if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi
|
|
|
|
if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi
|
|
|
|
if [ -n "$OPT_TITLE" ]; then set -- "$@" --es title "$OPT_TITLE"; fi
|
|
|
|
if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi
|
|
|
|
|
|
|
|
if [ -v OPT_CONTENT ]; then
|
|
|
|
# Note that we want to accept an empty content (--content "").
|
|
|
|
echo ${OPT_CONTENT:=""} | /data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
|
|
|
|
else
|
|
|
|
/data/data/com.termux/files/usr/libexec/termux-api Notification "$@"
|
|
|
|
fi
|