termux-api: Cleanups and fix whitespace handling

Fixes https://github.com/termux/termux-api/issues/20
This commit is contained in:
Fredrik Fornwall 2016-04-20 11:34:03 +02:00
parent f45321ca33
commit 8d6e165f62
5 changed files with 50 additions and 30 deletions

View File

@ -1,6 +1,6 @@
TERMUX_PKG_HOMEPAGE=http://termux.com/add-ons/api/
TERMUX_PKG_DESCRIPTION="Termux API commands"
TERMUX_PKG_VERSION=0.16
TERMUX_PKG_VERSION=0.17
termux_step_make_install () {
mkdir -p $TERMUX_PREFIX/bin

View File

@ -6,10 +6,10 @@ show_usage () {
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"
exit 0
}
@ -37,4 +37,8 @@ shift $(($OPTIND-1))
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 "$@"

View File

@ -1,30 +1,40 @@
#!/bin/sh
set -e -u
SCRIPTNAME=$0
SCRIPTNAME=termux-download
show_usage () {
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
done
shift $(($OPTIND-1))
# Too many arguments:
if [ $# != 1 ]; then show_usage; exit 1; fi
if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no url specified"; exit 1; fi
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
eval @TERMUX_API@ Download $PARAMS $1
URL_TO_DOWNLOAD="$1"
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
@TERMUX_API@ Download "$@"

View File

@ -3,7 +3,7 @@ set -e -u
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"
@ -43,4 +43,10 @@ if [ $CONTENT_OR_TITLE_SET = "no" ]; then
exit 1
fi
@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 "$@"

View File

@ -6,7 +6,7 @@ show_usage () {
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