You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

#!/bin/sh
set -e -u
10 years ago
SCRIPTNAME=termux-notification
10 years ago
show_usage () {
echo "Usage: termux-notification [-c content] [-i id] [-t title] [-u url]"
echo "Display a system notification."
echo ""
echo " -c content notification content to show"
echo " -i id notification id (will overwrite any previous notification"
echo " with the same id)"
echo " -t title notification title to show"
echo " -u url notification url when clicking on it"
echo ""
exit 0
10 years ago
}
CONTENT_OR_TITLE_SET=no
ARG_C=""
OPT_C=""
ARG_I=""
OPT_I=""
ARG_T=""
OPT_T=""
ARG_U=""
OPT_U=""
while getopts :hc:i:t:u: option
do
case "$option" in
h) show_usage;;
c) ARG_C="--es content"; OPT_C="$OPTARG"; CONTENT_OR_TITLE_SET=yes;;
i) ARG_I="--es id"; OPT_I="$OPTARG";;
t) ARG_T="--es title"; OPT_T="$OPTARG"; CONTENT_OR_TITLE_SET=yes;;
u) ARG_U="--es url"; OPT_U="$OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
10 years ago
done
shift $(($OPTIND-1))
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
10 years ago
if [ $CONTENT_OR_TITLE_SET = "no" ]; then
echo "$SCRIPTNAME: no title or content set"
exit 1
fi
10 years ago
set --
if [ -n "$ARG_C" ]; then set -- "$@" $ARG_C "$OPT_C"; fi
if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi
if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
if [ -n "$ARG_U" ]; then set -- "$@" $ARG_U "$OPT_U"; fi
@TERMUX_API@ Notification "$@"