termux-api: Cleanup and improve consistency

This commit is contained in:
Fredrik Fornwall 2016-04-26 01:37:45 +02:00
parent 8bfad7bca4
commit bea93fbd7a
17 changed files with 273 additions and 215 deletions

View File

@ -1,9 +1,23 @@
#!/bin/sh
set -e -u
if [ "$#" != "0" ]; then
echo "usage: termux-battery-status"
echo "Get the status of the device battery."
exit 1
fi
SCRIPTNAME=termux-battery-status
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "Get the status of the device battery."
echo ""
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@ BatteryStatus

View File

@ -1,3 +1,23 @@
#!/bin/sh
set -e -u
SCRIPTNAME=termux-camera-info
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "Get information about device camera(s)."
echo ""
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@ CameraInfo

View File

@ -1,29 +1,30 @@
#!/bin/sh
set -e -u
SCRIPTNAME=termux-camera-photo
show_usage () {
echo "usage: termux-camera-photo [OPTIONS] <output-file>"
echo ""
echo "Take a photo and save it in a file. Valid options:"
echo " -c, --camera <camera-id> the ID of the camera to use"
echo "Use termux-camera-info for information about available camera IDs."
echo "Usage: termux-camera-photo [-c camera-id] output-file"
echo "Take a photo and save it to a file in JPEG format."
echo ""
echo " -c camera-id ID of the camera to use (see termux-camera-info), default: 0"
echo ""
exit 0
}
PARAMS=""
O=`getopt -l camera: -l help -l size -- c:hs: "$@"`
eval set -- "$O"
while true; do
case "$1" in
-c|--camera) PARAMS="$PARAMS --es camera $2"; shift 2;;
-h|--help) show_usage; exit 0;;
-s|--size) PARAMS="$PARAMS --ei size_index $2"; shift 2;;
--) shift; break;;
*) echo Error; exit 1;;
esac
done
if [ $# != 1 ]; then show_usage; exit 1; fi
PARAMS=""
while getopts :hc: option
do
case "$option" in
h) show_usage;;
c) PARAMS="--es camera $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
if [ $# = 0 ]; then echo "$SCRIPTNAME: missing file argument"; exit 1; fi
if [ $# != 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
touch $1
PARAMS="$PARAMS --es file `realpath $1`"

View File

@ -3,9 +3,10 @@ set -e -u
SCRIPTNAME=termux-clipboard-get
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "Get the system clipboard text."
exit 0
echo "Usage: $SCRIPTNAME"
echo "Get the system clipboard text."
echo ""
exit 0
}
while getopts :h option

View File

@ -3,12 +3,10 @@ set -e -u
SCRIPTNAME=termux-clipboard-set
show_usage () {
echo "Usage: $SCRIPTNAME <text>"
echo "Set the system clipboard text."
echo ""
echo "If no arguments are given the text to set is read from stdin,"
echo "otherwise all arguments given are used as the text to set."
exit 0
echo "Usage: $SCRIPTNAME [text]"
echo "Set the system clipboard text. The text to set is either supplied as arguments or read from stdin if no arguments are given."
echo ""
exit 0
}
while getopts :h option

View File

@ -1,10 +1,23 @@
#!/bin/sh
set -e -u
if [ "$#" != "0" ]; then
echo "usage: termux-contact-list"
echo "List all contacts."
exit
fi
SCRIPTNAME=termux-contact-list
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "List all contacts."
echo ""
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@ ContactList

View File

@ -3,14 +3,15 @@ set -e -u
SCRIPTNAME=termux-dialog
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"
exit 0
echo "Usage: $SCRIPTNAME [-i hint] [-m] [-p] [-t title]"
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 ""
exit 0
}
PARAMS=""

View File

@ -3,12 +3,13 @@ set -e -u
SCRIPTNAME=termux-download
show_usage () {
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
echo "Usage: $SCRIPTNAME [-d description] [-t title] 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"
echo ""
exit 0
}
ARG_D=""

View File

@ -1,28 +1,30 @@
#!/bin/sh
set -e -u
PARAMS=""
SCRIPTNAME=termux-notification
show_usage () {
echo "usage: termux-location [OPTIONS]"
echo "Get the device location. Options:"
echo " -r, --request kind of request(s) to make [once/last/updates] (default: once)"
echo " -p, --provider location provider [gps/network/passive] (default: gps)"
echo "usage: $SCRIPTNAME [-p provider] [-r request]"
echo "Get the device location."
echo ""
echo " -p provider location provider [gps/network/passive] (default: gps)"
echo " -r request kind of request to make [once/last/updates] (default: once)"
echo ""
exit 0
}
O=`busybox getopt -q -l request: -l provider: -- r:hp: "$@"`
if [ $? != 0 ] ; then show_usage; exit 1 ; fi
eval set -- "$O"
while true; do
case "$1" in
-h|--help) show_usage; exit 0;;
-r|--request) PARAMS="$PARAMS --es request $2"; shift 2;;
-p|--provider) PARAMS="$PARAMS --es provider $2"; shift 2;;
--) shift; break;;
*) echo Error; show_usage; exit 1;;
esac
done
PARAMS=""
# Too many arguments:
if [ $# != 0 ]; then show_usage; exit 1; fi
while getopts :hr:p: option
do
case "$option" in
h) show_usage;;
r) PARAMS="$PARAMS --es request $OPTARG";;
p) PARAMS="$PARAMS --es provider $OPTARG";;
?) 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@ Location $PARAMS

View File

@ -3,14 +3,16 @@ set -e -u
SCRIPTNAME=termux-notification
show_usage () {
echo "Usage: termux-notification [OPTIONS]"
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
echo "Usage: termux-notification [-c content] [-i id] [-t title] [-u url]"
echo "Display a system notification."
echo ""
echo " -c content notification content to show"
echo " -i id notification id (will overwrite any previous notification"
echo " with the same id)"
echo " -t title notification title to show"
echo " -u url notification url when clicking on it"
echo ""
exit 0
}
CONTENT_OR_TITLE_SET=no

View File

@ -1,52 +1,51 @@
#!/bin/sh
set -e -u
SCRIPTNAME=termux-share
show_usage () {
echo "usage: termux-share [options] [file]"
echo "Share a file specified as argument or the stdin as text input."
echo "Options:"
echo " -a, --action which action to performed on the shared content: edit/send/view (default:view)"
echo " -d, --default share to the default receiver if one is selected (instead of showing a chooser)"
echo " -t, --title title to use for shared content (default: shared file name)"
echo " -c, --content-type content-type to use (default: guessed from file extension, text/plain for stdin)"
echo "Usage: $SCRIPTNAME [-a action] [-c content-type] [-d] [-t title] [file]"
echo "Share a file specified as argument or the text received on stdin if no file argument is given."
echo ""
echo " -a action which action to performed on the shared content:"
echo " edit/send/view (default:view)"
echo " -c content-type content-type to use (default: guessed from file extension,"
echo " text/plain for stdin)"
echo " -d share to the default receiver if one is selected"
echo " instead of showing a chooser"
echo " -t title title to use for shared content (default: shared file name)"
echo ""
exit 0
}
validate_share () {
SHARETYPE=$1
case "$SHARETYPE" in
edit)
;;
send)
;;
view)
;;
*)
echo "Unsupported action: '$SHARETYPE' - only edit/send/view available"
exit 1
;;
esac
SHARETYPE=$1
case "$SHARETYPE" in
edit) ;;
send) ;;
view) ;;
*) echo "$SCRIPTNAME: Unsupported action: '$SHARETYPE'"; exit 1;;
esac
}
PARAMS=""
O=`busybox getopt -q -l action: -l content-type: -l default -l help -l mimetype -l title: -- a:c:dht: "$@"`
if [ $? != 0 ] ; then show_usage; exit 1 ; fi
eval set -- "$O"
while true; do
case "$1" in
-a|--action) validate_share $2; PARAMS="$PARAMS --es action $2"; shift 2;;
-c|--content-type) PARAMS="$PARAMS --es content-type $2"; shift 2;;
-d|--default) PARAMS="$PARAMS --ez default-receiver true"; shift 1;;
-h|--help) show_usage; exit 0;;
-t|--title) PARAMS="$PARAMS --es title $2"; shift 2;;
--) shift; break;;
*) echo Error; exit 1;;
esac
while getopts :ha:c:dt: option
do
case "$option" in
h) show_usage;;
a) validate_share $OPTARG; PARAMS="$PARAMS --es action $OPTARG";;
c) PARAMS="$PARAMS --es content-type $OPTARG";;
d) PARAMS="$PARAMS --ez default-receiver true";;
t) PARAMS="$PARAMS --es title $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
if [ $# -gt 1 ]; then echo "Only one file can be shared"; exit 1; fi
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
if [ $# != 0 ]; then
# Note that the file path can contain whitespace.
@TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
# Note that the file path can contain whitespace.
@TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
else
@TERMUX_API@ Share $PARAMS
@TERMUX_API@ Share $PARAMS
fi

View File

@ -5,36 +5,33 @@ PARAM_LIMIT=10
PARAM_OFFSET=0
PARAMS=""
SCRIPTNAME=$0
SCRIPTNAME=termux-sms-inbox
show_usage () {
echo "usage: termux-sms-inbox [OPTIONS]"
echo "List received SMS messages."
echo ""
echo "Options are all optional."
echo " -d, --show-dates show dates"
echo " -n, --show-phone-numbers show phone numbers"
echo " -o, --offset offset in sms list (default: $PARAM_OFFSET)"
echo " -l, --limit offset in sms list (default: $PARAM_LIMIT)"
echo "Usage: termux-sms-inbox [-d] [-l limit] [-n] [-o offset]"
echo "List received SMS messages."
echo ""
echo " -d show dates when messages were created"
echo " -l limit offset in sms list (default: $PARAM_LIMIT)"
echo " -n show phone numbers"
echo " -o offset offset in sms list (default: $PARAM_OFFSET)"
echo ""
exit 0
}
O=`busybox getopt -q -l help -l show-dates -l show-phone-numbers -l limit: -l offset: -- dhl:no: "$@"`
if [ $? != 0 ] ; then show_usage; exit 1 ; fi
eval set -- "$O"
while true; do
case "$1" in
-h|--help) show_usage; exit 0;;
-l|--limit) PARAM_LIMIT=$2; shift 2;;
-o|--offset) PARAM_OFFSET=$2; shift 2;;
-d|--show-dates) PARAMS="$PARAMS --ez show-dates true"; shift;;
-n|--show-phone-numbers) PARAMS="$PARAMS --ez show-phone-numbers true"; shift;;
--) shift; break;;
*) echo Error; exit 1;;
esac
while getopts :hdl:no: option
do
case "$option" in
h) show_usage;;
d) PARAMS="$PARAMS --ez show-dates true";;
l) PARAM_LIMIT=$OPTARG;;
n) PARAMS="$PARAMS --ez show-phone-numbers true";;
o) PARAM_OFFSET=$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
PARAMS="$PARAMS --ei offset $PARAM_OFFSET --ei limit $PARAM_LIMIT"
@TERMUX_API@ SmsInbox $PARAMS

View File

@ -3,33 +3,32 @@ set -e -u
SCRIPTNAME=termux-sms-send
show_usage () {
echo "Usage: $SCRIPTNAME [-t <text>] <recipient-number>"
echo "Send a SMS."
echo ""
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 "Usage: $SCRIPTNAME -n number[,number2,number3,...] [text]"
echo "Send a SMS message to the specified recipient number(s). The text to send is either supplied as arguments or read from stdin if no arguments are given."
echo ""
echo " -n number(s) recipient number(s) - separate multiple numbers by commas"
echo ""
exit 0
}
TEXT_TO_SEND=""
while getopts :ht: option
RECIPIENTS=""
while getopts :hn: option
do
case "$option" in
h) show_usage;;
t) TEXT_TO_SEND="$OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
case "$option" in
h) show_usage;;
n) RECIPIENTS="--esa recipients $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
if [ $# = 0 ]; then echo "$SCRIPTNAME: too few arguments"; exit 1; fi
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
CMD="@TERMUX_API@ SmsSend --es recipient $1"
if [ -z "$TEXT_TO_SEND" ]; then
$CMD
else
echo $TEXT_TO_SEND | $CMD
if [ -z "$RECIPIENTS" ]; then
echo "$SCRIPTNAME: no recipient number given"; exit 1;
fi
CMD="@TERMUX_API@ SmsSend $RECIPIENTS"
if [ $# = 0 ]; then
$CMD
else
echo $@ | $CMD
fi

View File

@ -1,24 +1,30 @@
#!/bin/sh
set -e -u
SCRIPTNAME=termux-toast
show_usage () {
echo "usage: termux-toast [-s|--short]"
echo "Show the text from stdin in a Toast (a transient popup). Options:"
echo " -s, --short only show the toast for a short while"
echo "Usage: termux-toast [-s] [text]"
echo "Show text in a Toast (a transient popup). The text to show is either supplied as arguments or read from stdin if no arguments are given."
echo ""
echo " -s only show the toast for a short while"
echo ""
exit 0
}
PARAMS=""
O=`busybox getopt -q -l short -l help -- sh "$@"`
if [ $? != 0 ] ; then show_usage; exit 1 ; fi
eval set -- "$O"
while true; do
case "$1" in
-s|--short) PARAMS="$PARAMS --ez short true"; shift 1;;
-h|--help) show_usage; exit 0;;
--) shift; break;;
*) echo Error; exit 1;;
esac
while getopts :hs option
do
case "$option" in
h) show_usage;;
s) PARAMS="--ez short true";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
if [ $# != 0 ]; then show_usage; exit 1; fi
@TERMUX_API@ Toast $PARAMS
CMD="@TERMUX_API@ Toast $PARAMS"
if [ $# = 0 ]; then
$CMD
else
echo $@ | $CMD
fi

View File

@ -3,11 +3,10 @@ set -e -u
SCRIPTNAME=termux-tts-engines
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "Get information about the available text-to-speech (TTS) engines."
echo ""
echo "The name of an engine may be given to the termux-tts-speak command using the -e option."
exit 0
echo "Usage: $SCRIPTNAME"
echo "Get information about the available text-to-speech (TTS) engines. The name of an engine may be given to the termux-tts-speak command using the -e option."
echo ""
exit 0
}
while getopts :h option

View File

@ -3,41 +3,45 @@ set -e -u
SCRIPTNAME=termux-tts-speak
show_usage () {
echo "Usage: $SCRIPTNAME [OPTIONS] <text-to-speak>"
echo "Speak stdin input with a system text-to-speech (TTS) engine."
echo ""
echo " -e <engine> TTS engine to use (see 'termux-tts-engines')"
echo " -l <language> language to speak in (may be unsupported by the engine)"
echo " -p <pitch> pitch to use in speech. 1.0 is the normal pitch,"
echo " lower values lower the tone of the synthesized voice,"
echo " greater values increase it."
echo " -r <rate> speech rate to use. 1.0 is the normal speech rate,"
echo " lower values slow down the speech (0.5 is half the normal speech rate),"
echo " greater values accelerate it ({@code 2.0} is twice the normal speech rate)."
echo ""
echo "The text to send can be specified either as arguments or on stdin if no arguments are given."
exit 0
echo "Usage: $SCRIPTNAME [-e engine] [-l language] [-p pitch] [-r rate] [-s stream] [text-to-speak]"
echo "Speak text with a system text-to-speech (TTS) engine. The text to speak is either supplied as arguments or read from stdin if no arguments are given."
echo ""
echo " -e engine TTS engine to use (see termux-tts-engines)"
echo " -l language language to speak in (may be unsupported by the engine)"
echo " -p pitch pitch to use in speech. 1.0 is the normal pitch,"
echo " lower values lower the tone of the synthesized voice,"
echo " greater values increase it."
echo " -r rate speech rate to use. 1.0 is the normal speech rate,"
echo " lower values slow down the speech"
echo " (0.5 is half the normal speech rate)"
echo " while greater values accelerates it"
echo " (2.0 is twice the normal speech rate)."
echo " -s stream audio stream to use (default:NOTIFICATION), one of:"
echo " ALARM, MUSIC, NOTIFICATION, RING, SYSTEM, VOICE_CALL"
echo ""
exit 0
}
PARAMS=""
while getopts :he:l:p:r: option
while getopts :he:l:p:r:s: option
do
case "$option" in
h) show_usage;;
e) PARAMS="$PARAMS --es engine $OPTARG";;
l) PARAMS="$PARAMS --es language $OPTARG";;
p) PARAMS="$PARAMS --ef pitch $OPTARG";;
r) PARAMS="$PARAMS --ef rate $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
case "$option" in
h) show_usage;;
e) PARAMS="$PARAMS --es engine $OPTARG";;
l) PARAMS="$PARAMS --es language $OPTARG";;
p) PARAMS="$PARAMS --ef pitch $OPTARG";;
r) PARAMS="$PARAMS --ef rate $OPTARG";;
s) PARAMS="$PARAMS --es stream $OPTARG";;
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
CMD="@TERMUX_API@ TextToSpeech $PARAMS"
if [ $# = 0 ]; then
$CMD
$CMD
else
echo $@ | $CMD
echo $@ | $CMD
fi

View File

@ -3,12 +3,13 @@ set -e -u
SCRIPTNAME=termux-vibrate
show_usage () {
echo "Usage: $SCRIPTNAME [OPTIONS]"
echo "Vibrate the device."
echo ""
echo " -d <duration_ms> the duration to vibrate in ms (default:1000)"
echo " -f force vibration even in silent mode"
exit 0
echo "Usage: $SCRIPTNAME [-d duration] [-f]"
echo "Vibrate the device."
echo ""
echo " -d duration the duration to vibrate in ms (default:1000)"
echo " -f force vibration even in silent mode"
echo ""
exit 0
}
PARAMS=""