Browse Source

termux-api: Cleanup and improve consistency

android-5
Fredrik Fornwall 9 years ago
parent
commit
bea93fbd7a
  1. 22
      packages/termux-api/termux-battery-status
  2. 20
      packages/termux-api/termux-camera-info
  3. 31
      packages/termux-api/termux-camera-photo
  4. 1
      packages/termux-api/termux-clipboard-get
  5. 6
      packages/termux-api/termux-clipboard-set
  6. 21
      packages/termux-api/termux-contact-list
  7. 7
      packages/termux-api/termux-dialog
  8. 7
      packages/termux-api/termux-download
  9. 36
      packages/termux-api/termux-location
  10. 14
      packages/termux-api/termux-notification
  11. 59
      packages/termux-api/termux-share
  12. 41
      packages/termux-api/termux-sms-inbox
  13. 25
      packages/termux-api/termux-sms-send
  14. 36
      packages/termux-api/termux-toast
  15. 3
      packages/termux-api/termux-tts-engines
  16. 24
      packages/termux-api/termux-tts-speak
  17. 5
      packages/termux-api/termux-vibrate

22
packages/termux-api/termux-battery-status

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

20
packages/termux-api/termux-camera-info

@ -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

31
packages/termux-api/termux-camera-photo

@ -1,29 +1,30 @@
#!/bin/sh
set -e -u
SCRIPTNAME=termux-camera-photo
show_usage () {
echo "usage: termux-camera-photo [OPTIONS] <output-file>"
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 ""
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."
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;;
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 [ $# != 1 ]; then show_usage; exit 1; fi
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`"

1
packages/termux-api/termux-clipboard-get

@ -5,6 +5,7 @@ SCRIPTNAME=termux-clipboard-get
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "Get the system clipboard text."
echo ""
exit 0
}

6
packages/termux-api/termux-clipboard-set

@ -3,11 +3,9 @@ set -e -u
SCRIPTNAME=termux-clipboard-set
show_usage () {
echo "Usage: $SCRIPTNAME <text>"
echo "Set the system clipboard text."
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 ""
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
}

21
packages/termux-api/termux-contact-list

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

7
packages/termux-api/termux-dialog

@ -3,13 +3,14 @@ set -e -u
SCRIPTNAME=termux-dialog
show_usage () {
echo "Usage: $SCRIPTNAME [OPTIONS]"
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 " -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 " -t title the title to show for the input prompt"
echo ""
exit 0
}

7
packages/termux-api/termux-download

@ -3,11 +3,12 @@ set -e -u
SCRIPTNAME=termux-download
show_usage () {
echo "Usage: $SCRIPTNAME [OPTIONS] <url-to-download>"
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 " -d description description for the download request notification"
echo " -t title title for the download request notification"
echo ""
exit 0
}

36
packages/termux-api/termux-location

@ -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;;
PARAMS=""
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))
# Too many arguments:
if [ $# != 0 ]; then show_usage; exit 1; fi
if [ $# != 0 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
@TERMUX_API@ Location $PARAMS

14
packages/termux-api/termux-notification

@ -3,14 +3,16 @@ set -e -u
SCRIPTNAME=termux-notification
show_usage () {
echo "Usage: termux-notification [OPTIONS]"
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 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 " -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

59
packages/termux-api/termux-share

@ -1,48 +1,47 @@
#!/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
;;
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;;
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.

41
packages/termux-api/termux-sms-inbox

@ -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 "Usage: termux-sms-inbox [-d] [-l limit] [-n] [-o offset]"
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 " -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;;
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

25
packages/termux-api/termux-sms-send

@ -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 "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 " -t <text> text to send (optional - else from stdin)"
echo " -n number(s) recipient number(s) - separate multiple numbers by commas"
echo ""
echo "If no text is specified with the -t option the text to send is read from stdin."
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";;
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
if [ -z "$RECIPIENTS" ]; then
echo "$SCRIPTNAME: no recipient number given"; exit 1;
fi
CMD="@TERMUX_API@ SmsSend --es recipient $1"
if [ -z "$TEXT_TO_SEND" ]; then
CMD="@TERMUX_API@ SmsSend $RECIPIENTS"
if [ $# = 0 ]; then
$CMD
else
echo $TEXT_TO_SEND | $CMD
echo $@ | $CMD
fi

36
packages/termux-api/termux-toast

@ -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;;
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

3
packages/termux-api/termux-tts-engines

@ -4,9 +4,8 @@ set -e -u
SCRIPTNAME=termux-tts-engines
show_usage () {
echo "Usage: $SCRIPTNAME"
echo "Get information about the available text-to-speech (TTS) engines."
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 ""
echo "The name of an engine may be given to the termux-tts-speak command using the -e option."
exit 0
}

24
packages/termux-api/termux-tts-speak

@ -3,25 +3,28 @@ 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 "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 " -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 " -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 ""
echo "The text to send can be specified either as arguments or on stdin if no arguments are given."
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;;
@ -29,6 +32,7 @@ do
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

5
packages/termux-api/termux-vibrate

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

Loading…
Cancel
Save