| 1 | #!/bin/bash |
| 2 | set -e -u |
| 3 | |
| 4 | SCRIPTNAME=termux-notification |
| 5 | show_usage () { |
| 6 | echo "Usage: termux-notification [-c content] [-i id] [-t title] [-u url]" |
| 7 | echo "Display a system notification." |
| 8 | echo "" |
| 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" |
| 19 | echo "" |
| 20 | exit 0 |
| 21 | } |
| 22 | |
| 23 | CONTENT_OR_TITLE_SET=no |
| 24 | ARG_C="" |
| 25 | OPT_C="" |
| 26 | OPT_ID="" |
| 27 | ARG_T="" |
| 28 | OPT_T="" |
| 29 | ARG_U="" |
| 30 | OPT_U="" |
| 31 | OPT_PRIORITY="" |
| 32 | OPT_LED_COLOR="" |
| 33 | OPT_LED_ON="" |
| 34 | OPT_LED_OFF="" |
| 35 | OPT_VIBRATE="" |
| 36 | OPT_SOUND="" |
| 37 | |
| 38 | TEMP=`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 | -- "$@"` |
| 44 | eval set -- "$TEMP" |
| 45 | |
| 46 | while 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 ;; |
| 60 | esac |
| 61 | done |
| 62 | |
| 63 | if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
| 64 | |
| 65 | if [ $CONTENT_OR_TITLE_SET = "no" ]; then |
| 66 | echo "$SCRIPTNAME: no title or content set" |
| 67 | exit 1 |
| 68 | fi |
| 69 | |
| 70 | set -- |
| 71 | if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi |
| 72 | if [ -n "$OPT_ID" ]; then set -- "$@" --es id "$OPT_ID"; fi |
| 73 | if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi |
| 74 | if [ -n "$ARG_U" ]; then set -- "$@" $ARG_U "$OPT_U"; fi |
| 75 | if [ -n "$OPT_LED_COLOR" ]; then set -- "$@" --es led-color "$OPT_LED_COLOR"; fi |
| 76 | if [ -n "$OPT_LED_ON" ]; then set -- "$@" --ei led-on "$OPT_LED_ON"; fi |
| 77 | if [ -n "$OPT_LED_OFF" ]; then set -- "$@" --ei led-off "$OPT_LED_OFF"; fi |
| 78 | if [ -n "$OPT_PRIORITY" ]; then set -- "$@" --es priority "$OPT_PRIORITY"; fi |
| 79 | if [ -n "$OPT_SOUND" ]; then set -- "$@" --ez sound "$OPT_SOUND"; fi |
| 80 | if [ -n "$OPT_VIBRATE" ]; then set -- "$@" --ela vibrate "$OPT_VIBRATE"; fi |
| 81 | |
| 82 | @TERMUX_API@ Notification "$@" |