notmuch: Add package
[termux-packages] / packages / termux-api / termux-share
... / ...
CommitLineData
1#!/bin/sh
2set -e -u
3
4SCRIPTNAME=termux-share
5show_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
18validate_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
28PARAMS=""
29while getopts :ha:c:dt: option
30do
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
39done
40shift $(($OPTIND-1))
41
42if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
43
44if [ $# != 0 ]; then
45 # Note that the file path can contain whitespace.
46 @TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
47else
48 @TERMUX_API@ Share $PARAMS
49fi