termux-api: Cleanups and fix whitespace handling
authorFredrik Fornwall <fredrik@fornwall.net>
Wed, 20 Apr 2016 09:34:03 +0000 (11:34 +0200)
committerFredrik Fornwall <fredrik@fornwall.net>
Wed, 20 Apr 2016 09:34:54 +0000 (11:34 +0200)
Fixes https://github.com/termux/termux-api/issues/20

packages/termux-api/build.sh
packages/termux-api/termux-dialog
packages/termux-api/termux-download
packages/termux-api/termux-notification
packages/termux-api/termux-sms-send

index 8746517..9a51a1b 100644 (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
index d968453..c513f94 100755 (executable)
@@ -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 "$@"
index c7b8fea..f8e3f97 100755 (executable)
@@ -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))
+
+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 "$@"
index 96a0e2a..34a5aab 100755 (executable)
@@ -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 "$@"
index 43664a5..7802b07 100755 (executable)
@@ -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