vim: Update to latest patch level
[termux-packages] / packages / termux-api / termux-share
1 #!/bin/sh
2 set -e -u
3
4 SCRIPTNAME=termux-share
5 show_usage () {
6 echo "Usage: $SCRIPTNAME [-a action] [-c content-type] [-d] [-t title] [file]"
7 echo "Share a file specified as argument or the text received on stdin if no file argument is given."
8 echo " -a action which action to performed on the shared content:"
9 echo " edit/send/view (default:view)"
10 echo " -c content-type content-type to use (default: guessed from file extension,"
11 echo " text/plain for stdin)"
12 echo " -d share to the default receiver if one is selected"
13 echo " instead of showing a chooser"
14 echo " -t title title to use for shared content (default: shared file name)"
15 exit 0
16 }
17
18 validate_share () {
19 SHARETYPE=$1
20 case "$SHARETYPE" in
21 edit) ;;
22 send) ;;
23 view) ;;
24 *) echo "$SCRIPTNAME: Unsupported action: '$SHARETYPE'"; exit 1;;
25 esac
26 }
27
28 PARAMS=""
29 while getopts :ha:c:dt: option
30 do
31 case "$option" in
32 h) show_usage;;
33 a) validate_share $OPTARG; PARAMS="$PARAMS --es action $OPTARG";;
34 c) PARAMS="$PARAMS --es content-type $OPTARG";;
35 d) PARAMS="$PARAMS --ez default-receiver true";;
36 t) PARAMS="$PARAMS --es title $OPTARG";;
37 ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
38 esac
39 done
40 shift $(($OPTIND-1))
41
42 if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
43
44 if [ $# != 0 ]; then
45 # Note that the file path can contain whitespace.
46 @TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
47 else
48 @TERMUX_API@ Share $PARAMS
49 fi