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 |
#!/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 |
@TERMUX_API@ Clipboard |
||||
|
@ -1,34 +1,40 @@ |
|||||
#!/bin/sh |
#!/bin/sh |
||||
|
|
||||
set -e -u |
set -e -u |
||||
|
|
||||
SCRIPTNAME=$0 |
SCRIPTNAME=termux-dialog |
||||
show_usage () { |
show_usage () { |
||||
echo "usage: $SCRIPTNAME [OPTIONS]" |
echo "Usage: $SCRIPTNAME [OPTIONS]" |
||||
echo "Show a text entry dialog." |
echo "Show a text entry dialog." |
||||
echo " -i, --input-hint <hint> The input hint to show when the input is empty" |
echo "" |
||||
echo " -m, --multiple-lines Use a textarea with multiple lines instead of a single" |
echo " -i <hint> The input hint to show when the input is empty" |
||||
echo " -p, --password Enter the input as a password" |
echo " -m Use a textarea with multiple lines instead of a single" |
||||
echo " -t, --title <title> The title to show for the input prompt" |
echo " -p Enter the input as a password" |
||||
|
echo " -t <title> The title to show for the input prompt" |
||||
|
exit 0 |
||||
} |
} |
||||
|
|
||||
PARAMS="" |
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 |
ARG_I="" |
||||
eval set -- "$O" |
OPT_I="" |
||||
while true; do |
ARG_M="" |
||||
case "$1" in |
ARG_P="" |
||||
-h|--help) show_usage; exit 0;; |
ARG_T="" |
||||
-i|--input-hint) PARAMS="$PARAMS --es input_hint '$2'"; shift 2;; |
OPT_T="" |
||||
-m|--multiple-lines) PARAMS="$PARAMS --ez multiple_lines true"; shift 1;; |
|
||||
-p|--password) PARAMS="$PARAMS --es input_type password"; shift 1;; |
while getopts :hi:mpt: option |
||||
-t|--title) PARAMS="$PARAMS --es input_title '$2'"; shift 2;; |
do |
||||
--) shift; break;; |
case "$option" in |
||||
*) echo Error; exit 1;; |
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 |
esac |
||||
done |
done |
||||
|
shift $(($OPTIND-1)) |
||||
|
|
||||
# Too many arguments: |
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
||||
if [ $# != 0 ]; then show_usage; 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 |
#!/bin/sh |
||||
|
set -e -u |
||||
|
|
||||
set -u |
SCRIPTNAME=termux-notification |
||||
|
|
||||
PARAMS="" |
|
||||
CONTENT_OR_TITLE_SET=no |
|
||||
|
|
||||
SCRIPTNAME=$0 |
|
||||
show_usage () { |
show_usage () { |
||||
echo "usage: termux-notification [OPTIONS]" |
echo "usage: termux-notification [OPTIONS]" |
||||
echo "Display a notification. Options:" |
echo "Display a system notification." |
||||
echo " -c, --content <content> notification content to show" |
echo "" |
||||
echo " -i, --id <id> notification id (will overwrite the previous notification with the same id)" |
echo " -c <content> notification content to show" |
||||
echo " -t, --title <title> notification title to show" |
echo " -i <id> notification id (will overwrite the previous notification with the same id)" |
||||
echo " -u, --url <url> notification url when clicking on it" |
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: "$@"` |
CONTENT_OR_TITLE_SET=no |
||||
if [ $? != 0 ] ; then show_usage; exit 1 ; fi |
ARG_C="" |
||||
eval set -- "$O" |
OPT_C="" |
||||
while true; do |
ARG_I="" |
||||
case "$1" in |
OPT_I="" |
||||
-c|--content) PARAMS="$PARAMS --es content '$2'"; CONTENT_OR_TITLE_SET=yes; shift 2;; |
ARG_T="" |
||||
-h|--help) show_usage; exit 0;; |
OPT_T="" |
||||
-i|--id) PARAMS="$PARAMS --es id $2"; shift 2;; |
ARG_U="" |
||||
-t|--title) PARAMS="$PARAMS --es title '$2'"; CONTENT_OR_TITLE_SET=yes; shift 2;; |
OPT_U="" |
||||
-u|--url) PARAMS="$PARAMS --es url '$2'"; shift 2;; |
|
||||
--) shift; break;; |
while getopts :hc:i:t:u: option |
||||
*) echo Error; exit 1;; |
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 |
esac |
||||
done |
done |
||||
|
shift $(($OPTIND-1)) |
||||
|
|
||||
|
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi |
||||
|
|
||||
if [ $CONTENT_OR_TITLE_SET = "no" ]; then |
if [ $CONTENT_OR_TITLE_SET = "no" ]; then |
||||
show_usage |
echo "$SCRIPTNAME: no title or content set" |
||||
exit 1; |
exit 1 |
||||
fi; |
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