Commit | Line | Data |
---|---|---|
cc1ae02e | 1 | #!/bin/sh |
0ec2b704 | 2 | set -e -u |
59f0d218 | 3 | |
0ec2b704 | 4 | SCRIPTNAME=termux-notification |
59f0d218 | 5 | show_usage () { |
bea93fbd FF |
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 notification content to show" | |
10 | echo " -i id notification id (will overwrite any previous notification" | |
11 | echo " with the same id)" | |
12 | echo " -t title notification title to show" | |
13 | echo " -u url notification url when clicking on it" | |
14 | echo "" | |
15 | exit 0 | |
59f0d218 FF |
16 | } |
17 | ||
0ec2b704 FF |
18 | CONTENT_OR_TITLE_SET=no |
19 | ARG_C="" | |
20 | OPT_C="" | |
21 | ARG_I="" | |
22 | OPT_I="" | |
23 | ARG_T="" | |
24 | OPT_T="" | |
25 | ARG_U="" | |
26 | OPT_U="" | |
27 | ||
28 | while getopts :hc:i:t:u: option | |
29 | do | |
30 | case "$option" in | |
31 | h) show_usage;; | |
32 | c) ARG_C="--es content"; OPT_C="$OPTARG"; CONTENT_OR_TITLE_SET=yes;; | |
33 | i) ARG_I="--es id"; OPT_I="$OPTARG";; | |
34 | t) ARG_T="--es title"; OPT_T="$OPTARG"; CONTENT_OR_TITLE_SET=yes;; | |
35 | u) ARG_U="--es url"; OPT_U="$OPTARG";; | |
36 | ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; | |
37 | esac | |
59f0d218 | 38 | done |
0ec2b704 FF |
39 | shift $(($OPTIND-1)) |
40 | ||
41 | if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi | |
59f0d218 FF |
42 | |
43 | if [ $CONTENT_OR_TITLE_SET = "no" ]; then | |
0ec2b704 FF |
44 | echo "$SCRIPTNAME: no title or content set" |
45 | exit 1 | |
46 | fi | |
59f0d218 | 47 | |
8d6e165f FF |
48 | set -- |
49 | if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi | |
50 | if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi | |
51 | if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi | |
52 | if [ -n "$ARG_U" ]; then set -- "$@" $ARG_U "$OPT_U"; fi | |
53 | ||
54 | @TERMUX_API@ Notification "$@" |