notmuch: Add package
[termux-packages] / packages / termux-api / termux-share
CommitLineData
cc1ae02e 1#!/bin/sh
bea93fbd 2set -e -u
1ee4335f 3
bea93fbd 4SCRIPTNAME=termux-share
1ee4335f 5show_usage () {
bea93fbd
FF
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."
bea93fbd
FF
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)"
bea93fbd 15 exit 0
1ee4335f
FF
16}
17
18validate_share () {
bea93fbd
FF
19 SHARETYPE=$1
20 case "$SHARETYPE" in
21 edit) ;;
22 send) ;;
23 view) ;;
24 *) echo "$SCRIPTNAME: Unsupported action: '$SHARETYPE'"; exit 1;;
25 esac
1ee4335f
FF
26}
27
28PARAMS=""
bea93fbd
FF
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
1ee4335f 39done
bea93fbd 40shift $(($OPTIND-1))
1ee4335f 41
bea93fbd 42if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
1ee4335f 43
fa5ce6c4 44if [ $# != 0 ]; then
bea93fbd
FF
45 # Note that the file path can contain whitespace.
46 @TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
fa5ce6c4 47else
bea93fbd 48 @TERMUX_API@ Share $PARAMS
fa5ce6c4 49fi