Fixes https://github.com/termux/termux-api/issues/20
TERMUX_PKG_HOMEPAGE=http://termux.com/add-ons/api/
TERMUX_PKG_DESCRIPTION="Termux API commands"
TERMUX_PKG_HOMEPAGE=http://termux.com/add-ons/api/
TERMUX_PKG_DESCRIPTION="Termux API commands"
termux_step_make_install () {
mkdir -p $TERMUX_PREFIX/bin
termux_step_make_install () {
mkdir -p $TERMUX_PREFIX/bin
echo "Usage: $SCRIPTNAME [OPTIONS]"
echo "Show a text entry dialog."
echo ""
echo "Usage: $SCRIPTNAME [OPTIONS]"
echo "Show a text entry dialog."
echo ""
- echo " -i <hint> The input hint to show when the input is empty"
- echo " -m Use a textarea with multiple lines instead of a single"
- echo " -p Enter the input as a password"
- echo " -t <title> The title to show for the input prompt"
+ echo " -i <hint> the input hint to show when the input is empty"
+ echo " -m use a textarea with multiple lines instead of a single"
+ echo " -p enter the input as a password"
+ echo " -t <title> the title to show for the input prompt"
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
-@TERMUX_API@ Dialog $ARG_I "$OPT_I" $ARG_M $ARG_P $ARG_T "$OPT_T"
+set -- $ARG_M $ARG_P
+if [ -n "$ARG_I" ]; then set -- "$@" $ARG_I "$OPT_I"; fi
+if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
+
+@TERMUX_API@ Dialog "$@"
+SCRIPTNAME=termux-download
- echo "usage: termux-download <uri-to-download>"
- echo " Download a resource using the system download manager."
- echo " -d, --description Description for the download request notification"
- echo " -t, --title Title for the download request notification"
+ echo "Usage: $SCRIPTNAME [OPTIONS] <url-to-download>"
+ echo "Download a resource using the system download manager."
+ echo ""
+ echo " -d <description> description for the download request notification"
+ echo " -t <title> title for the download request notification"
+ exit 0
-PARAMS=""
-O=`busybox getopt -q -l description: -l title: -l help -- d:t:h "$@"`
-if [ $? != 0 ] ; then show_usage; exit 1 ; fi
-eval set -- "$O"
-while true; do
-case "$1" in
- -h|--help) show_usage; exit 0;;
- -d|--description) PARAMS="$PARAMS --es description '$2'"; shift 2;;
- -t|--title) PARAMS="$PARAMS --es title '$2'"; shift 2;;
- --) shift; break;;
- *) echo Error; exit 1;;
-esac
+ARG_D=""
+OPT_D=""
+ARG_T=""
+OPT_T=""
+
+while getopts :hd:t: option
+do
+ case "$option" in
+ h) show_usage;;
+ d) ARG_D="--es description"; OPT_D="$OPTARG";;
+ t) ARG_T="--es title"; OPT_T="$OPTARG";;
+ ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
+ esac
+shift $(($OPTIND-1))
+
+if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi
+if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
+
+URL_TO_DOWNLOAD="$1"
-# Too many arguments:
-if [ $# != 1 ]; then show_usage; exit 1; fi
+set --
+if [ -n "$ARG_D" ]; then set -- "$@" $ARG_D "$OPT_D"; fi
+if [ -n "$ARG_T" ]; then set -- "$@" $ARG_T "$OPT_T"; fi
+set -- "$@" $URL_TO_DOWNLOAD
-eval @TERMUX_API@ Download $PARAMS $1
+@TERMUX_API@ Download "$@"
SCRIPTNAME=termux-notification
show_usage () {
SCRIPTNAME=termux-notification
show_usage () {
- echo "usage: termux-notification [OPTIONS]"
+ echo "Usage: termux-notification [OPTIONS]"
echo "Display a system notification."
echo ""
echo " -c <content> notification content to show"
echo "Display a system notification."
echo ""
echo " -c <content> notification content to show"
-@TERMUX_API@ Notification $ARG_C "$OPT_C" $ARG_I "$OPT_I" $ARG_T "$OPT_T" $ARG_U "$OPT_U"
+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 "$@"
echo "Usage: $SCRIPTNAME [-t <text>] <recipient-number>"
echo "Send a SMS."
echo ""
echo "Usage: $SCRIPTNAME [-t <text>] <recipient-number>"
echo "Send a SMS."
echo ""
- echo " -t <text> The text to send (optional - else from stdin)"
+ echo " -t <text> text to send (optional - else from stdin)"
echo ""
echo "If no text is specified with the -t option the text to send is read from stdin."
exit 0
echo ""
echo "If no text is specified with the -t option the text to send is read from stdin."
exit 0