Browse Source

termux-api: Cleanup and improve consistency

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

24
packages/termux-api/termux-battery-status

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

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

@ -1,3 +1,23 @@
#!/bin/sh #!/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 @TERMUX_API@ CameraInfo

35
packages/termux-api/termux-camera-photo

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

7
packages/termux-api/termux-clipboard-get

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

10
packages/termux-api/termux-clipboard-set

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

23
packages/termux-api/termux-contact-list

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

17
packages/termux-api/termux-dialog

@ -3,14 +3,15 @@ set -e -u
SCRIPTNAME=termux-dialog SCRIPTNAME=termux-dialog
show_usage () { show_usage () {
echo "Usage: $SCRIPTNAME [OPTIONS]" echo "Usage: $SCRIPTNAME [-i hint] [-m] [-p] [-t title]"
echo "Show a text entry dialog." echo "Show a text entry dialog."
echo "" 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 " -m use a textarea with multiple lines instead of a single"
echo " -p enter the input as a password" 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"
exit 0 echo ""
exit 0
} }
PARAMS="" PARAMS=""

13
packages/termux-api/termux-download

@ -3,12 +3,13 @@ set -e -u
SCRIPTNAME=termux-download SCRIPTNAME=termux-download
show_usage () { 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 "Download a resource using the system download manager."
echo "" echo ""
echo " -d <description> description for the download request notification" echo " -d description description for the download request notification"
echo " -t <title> title for the download request notification" echo " -t title title for the download request notification"
exit 0 echo ""
exit 0
} }
ARG_D="" ARG_D=""

38
packages/termux-api/termux-location

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

18
packages/termux-api/termux-notification

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

73
packages/termux-api/termux-share

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

47
packages/termux-api/termux-sms-inbox

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

41
packages/termux-api/termux-sms-send

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

38
packages/termux-api/termux-toast

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

9
packages/termux-api/termux-tts-engines

@ -3,11 +3,10 @@ set -e -u
SCRIPTNAME=termux-tts-engines SCRIPTNAME=termux-tts-engines
show_usage () { show_usage () {
echo "Usage: $SCRIPTNAME" 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 ""
echo "The name of an engine may be given to the termux-tts-speak command using the -e option." exit 0
exit 0
} }
while getopts :h option while getopts :h option

54
packages/termux-api/termux-tts-speak

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

13
packages/termux-api/termux-vibrate

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

Loading…
Cancel
Save