2018-06-22 06:58:40 +02:00
#!/data/data/com.termux/files/usr/bin/bash
2017-04-09 18:19:29 +02:00
set -e -u
SCRIPTNAME=termux-toast
show_usage () {
2018-06-22 06:58:40 +02:00
echo "Usage: termux-toast [-b bgcolor] [-c color] [-g gravity] [-s] [text]"
2017-04-09 18:19:29 +02:00
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."
2018-06-22 06:58:40 +02:00
echo " -h show this help"
echo " -b set background color (default: gray)"
echo " -c set text color (default: white)"
echo " -g set position of toast: [top, middle, or bottom] (default: middle)"
2017-04-09 18:19:29 +02:00
echo " -s only show the toast for a short while"
2018-06-22 06:58:40 +02:00
echo "NOTE: color can be a standard name (i.e. red) or 6 / 8 digit hex value (i.e. \"#FF0000\" or \"#FFFF0000\") where order is (AA)RRGGBB. Invalid color will revert to default value"
2017-04-09 18:19:29 +02:00
exit 0
}
PARAMS=""
2018-06-22 06:58:40 +02:00
while getopts :hsc:b:g: option
2017-04-09 18:19:29 +02:00
do
case "$option" in
h) show_usage;;
2019-03-23 19:49:38 +01:00
s) PARAMS+=" --ez short true";;
2018-06-22 06:58:40 +02:00
c) PARAMS+=" --es text_color $OPTARG";;
b) PARAMS+=" --es background $OPTARG";;
g) PARAMS+=" --es gravity $OPTARG";;
2017-04-09 18:19:29 +02:00
?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
esac
done
shift $(($OPTIND-1))
2017-04-09 19:00:20 +02:00
CMD="/data/data/com.termux/files/usr/libexec/termux-api Toast $PARAMS"
2018-06-22 06:58:40 +02:00
2017-04-09 18:19:29 +02:00
if [ $# = 0 ]; then
$CMD
else
echo $@ | $CMD
fi