Browse Source
Start using shell built-in getops and remove long arguments. Make both clipboard-set and sms-send either take argument or read from stdin. Fixes https://github.com/termux/termux-api/issues/14android-5
Fredrik Fornwall
9 years ago
6 changed files with 139 additions and 61 deletions
@ -1,3 +1,22 @@ |
|||
#!/bin/sh |
|||
set -e -u |
|||
|
|||
SCRIPTNAME=termux-clipboard-get |
|||
show_usage () { |
|||
echo "Usage: $SCRIPTNAME" |
|||
echo "Get the system clipboard text." |
|||
exit 0 |
|||
} |
|||
|
|||
while getopts :h option |
|||
do |
|||
case "$option" in |
|||
h) show_usage;; |
|||
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; |
|||
esac |
|||
done |
|||
shift $(($OPTIND-1)) |
|||
|
|||
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
|||
|
|||
@TERMUX_API@ Clipboard |
|||
|
@ -1,34 +1,40 @@ |
|||
#!/bin/sh |
|||
|
|||
set -e -u |
|||
|
|||
SCRIPTNAME=$0 |
|||
SCRIPTNAME=termux-dialog |
|||
show_usage () { |
|||
echo "usage: $SCRIPTNAME [OPTIONS]" |
|||
echo " Show a text entry dialog." |
|||
echo " -i, --input-hint <hint> The input hint to show when the input is empty" |
|||
echo " -m, --multiple-lines Use a textarea with multiple lines instead of a single" |
|||
echo " -p, --password Enter the input as a password" |
|||
echo " -t, --title <title> The title to show for the input prompt" |
|||
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" |
|||
exit 0 |
|||
} |
|||
|
|||
PARAMS="" |
|||
O=`busybox getopt -q -l help -l input-hint: -l multiple-lines -l password -l title: -- hi:mpt: "$@"` |
|||
if [ $? != 0 ] ; then show_usage; exit 1 ; fi |
|||
eval set -- "$O" |
|||
while true; do |
|||
case "$1" in |
|||
-h|--help) show_usage; exit 0;; |
|||
-i|--input-hint) PARAMS="$PARAMS --es input_hint '$2'"; shift 2;; |
|||
-m|--multiple-lines) PARAMS="$PARAMS --ez multiple_lines true"; shift 1;; |
|||
-p|--password) PARAMS="$PARAMS --es input_type password"; shift 1;; |
|||
-t|--title) PARAMS="$PARAMS --es input_title '$2'"; shift 2;; |
|||
--) shift; break;; |
|||
*) echo Error; exit 1;; |
|||
esac |
|||
|
|||
ARG_I="" |
|||
OPT_I="" |
|||
ARG_M="" |
|||
ARG_P="" |
|||
ARG_T="" |
|||
OPT_T="" |
|||
|
|||
while getopts :hi:mpt: option |
|||
do |
|||
case "$option" in |
|||
h) show_usage;; |
|||
i) ARG_I="--es input_hint"; OPT_I="$OPTARG";; |
|||
m) ARG_M="--ez multiple_lines true";; |
|||
p) ARG_P="--es input_type password";; |
|||
t) ARG_T="--es input_title"; OPT_T="$OPTARG";; |
|||
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; |
|||
esac |
|||
done |
|||
shift $(($OPTIND-1)) |
|||
|
|||
# Too many arguments: |
|||
if [ $# != 0 ]; then show_usage; exit 1; fi |
|||
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
|||
|
|||
eval @TERMUX_API@ Dialog $PARAMS |
|||
@TERMUX_API@ Dialog $ARG_I "$OPT_I" $ARG_M $ARG_P $ARG_T "$OPT_T" |
|||
|
@ -1,38 +1,46 @@ |
|||
#!/bin/sh |
|||
set -e -u |
|||
|
|||
set -u |
|||
|
|||
PARAMS="" |
|||
CONTENT_OR_TITLE_SET=no |
|||
|
|||
SCRIPTNAME=$0 |
|||
SCRIPTNAME=termux-notification |
|||
show_usage () { |
|||
echo "usage: termux-notification [OPTIONS]" |
|||
echo "Display a notification. Options:" |
|||
echo " -c, --content <content> notification content to show" |
|||
echo " -i, --id <id> notification id (will overwrite the previous notification with the same id)" |
|||
echo " -t, --title <title> notification title to show" |
|||
echo " -u, --url <url> notification url when clicking on it" |
|||
echo "Display a system notification." |
|||
echo "" |
|||
echo " -c <content> notification content to show" |
|||
echo " -i <id> notification id (will overwrite the previous notification with the same id)" |
|||
echo " -t <title> notification title to show" |
|||
echo " -u <url> notification url when clicking on it" |
|||
exit 1 |
|||
} |
|||
|
|||
O=`busybox getopt -q -l content: -l help -l title: -l id: -l url: -- c:hi:t:u: "$@"` |
|||
if [ $? != 0 ] ; then show_usage; exit 1 ; fi |
|||
eval set -- "$O" |
|||
while true; do |
|||
case "$1" in |
|||
-c|--content) PARAMS="$PARAMS --es content '$2'"; CONTENT_OR_TITLE_SET=yes; shift 2;; |
|||
-h|--help) show_usage; exit 0;; |
|||
-i|--id) PARAMS="$PARAMS --es id $2"; shift 2;; |
|||
-t|--title) PARAMS="$PARAMS --es title '$2'"; CONTENT_OR_TITLE_SET=yes; shift 2;; |
|||
-u|--url) PARAMS="$PARAMS --es url '$2'"; shift 2;; |
|||
--) shift; break;; |
|||
*) echo Error; exit 1;; |
|||
esac |
|||
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 |
|||
done |
|||
shift $(($OPTIND-1)) |
|||
|
|||
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
|||
|
|||
if [ $CONTENT_OR_TITLE_SET = "no" ]; then |
|||
show_usage |
|||
exit 1; |
|||
fi; |
|||
echo "$SCRIPTNAME: no title or content set" |
|||
exit 1 |
|||
fi |
|||
|
|||
eval @TERMUX_API@ Notification $PARAMS |
|||
@TERMUX_API@ Notification $ARG_C "$OPT_C" $ARG_I "$OPT_I" $ARG_T "$OPT_T" $ARG_U "$OPT_U" |
|||
|
Loading…
Reference in new issue