X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/17d445b3f3619ab39192331b20a99c349ed13f38..dd6f8fa7dfb2546c73b82c101d125129eea621f5:/packages/termux-api/termux-toast diff --git a/packages/termux-api/termux-toast b/packages/termux-api/termux-toast index e54b04f1..43a062c5 100755 --- a/packages/termux-api/termux-toast +++ b/packages/termux-api/termux-toast @@ -1,24 +1,30 @@ -#!/system/bin/sh +#!/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