termux-api: Cleanup and improve consistency
[termux-packages] / packages / termux-api / termux-notification
CommitLineData
cc1ae02e 1#!/bin/sh
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 ""
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
18CONTENT_OR_TITLE_SET=no
19ARG_C=""
20OPT_C=""
21ARG_I=""
22OPT_I=""
23ARG_T=""
24OPT_T=""
25ARG_U=""
26OPT_U=""
27
28while getopts :hc:i:t:u: option
29do
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 38done
0ec2b704
FF
39shift $(($OPTIND-1))
40
41if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
59f0d218
FF
42
43if [ $CONTENT_OR_TITLE_SET = "no" ]; then
0ec2b704
FF
44 echo "$SCRIPTNAME: no title or content set"
45 exit 1
46fi
59f0d218 47
8d6e165f
FF
48set --
49if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi
50if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi
51if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
52if [ -n "$ARG_U" ]; then set -- "$@" $ARG_U "$OPT_U"; fi
53
54@TERMUX_API@ Notification "$@"