2015-08-14 21:27:47 +02:00
|
|
|
#!/bin/sh
|
2016-04-26 01:37:45 +02:00
|
|
|
set -e -u
|
2015-07-29 03:50:54 +02:00
|
|
|
|
2016-04-26 01:37:45 +02:00
|
|
|
SCRIPTNAME=termux-share
|
2015-07-29 03:50:54 +02:00
|
|
|
show_usage () {
|
2016-04-26 01:37:45 +02:00
|
|
|
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 " -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)"
|
|
|
|
exit 0
|
2015-07-29 03:50:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
validate_share () {
|
2016-04-26 01:37:45 +02:00
|
|
|
SHARETYPE=$1
|
|
|
|
case "$SHARETYPE" in
|
|
|
|
edit) ;;
|
|
|
|
send) ;;
|
|
|
|
view) ;;
|
|
|
|
*) echo "$SCRIPTNAME: Unsupported action: '$SHARETYPE'"; exit 1;;
|
|
|
|
esac
|
2015-07-29 03:50:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PARAMS=""
|
2016-04-26 01:37:45 +02:00
|
|
|
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
|
2015-07-29 03:50:54 +02:00
|
|
|
done
|
2016-04-26 01:37:45 +02:00
|
|
|
shift $(($OPTIND-1))
|
2015-07-29 03:50:54 +02:00
|
|
|
|
2016-04-26 01:37:45 +02:00
|
|
|
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
|
2015-07-29 03:50:54 +02:00
|
|
|
|
2016-01-04 23:16:55 +01:00
|
|
|
if [ $# != 0 ]; then
|
2016-04-26 01:37:45 +02:00
|
|
|
# Note that the file path can contain whitespace.
|
|
|
|
@TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
|
2016-01-04 23:16:55 +01:00
|
|
|
else
|
2016-04-26 01:37:45 +02:00
|
|
|
@TERMUX_API@ Share $PARAMS
|
2016-01-04 23:16:55 +01:00
|
|
|
fi
|