libgcrypt: Revert from 1.7.4 to 1.7.3
[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."
8 echo ""
9 echo " -a action which action to performed on the shared content:"
10 echo " edit/send/view (default:view)"
11 echo " -c content-type content-type to use (default: guessed from file extension,"
12 echo " text/plain for stdin)"
13 echo " -d share to the default receiver if one is selected"
14 echo " instead of showing a chooser"
15 echo " -t title title to use for shared content (default: shared file name)"
16 echo ""
17 exit 0
1ee4335f
FF
18}
19
20validate_share () {
bea93fbd
FF
21 SHARETYPE=$1
22 case "$SHARETYPE" in
23 edit) ;;
24 send) ;;
25 view) ;;
26 *) echo "$SCRIPTNAME: Unsupported action: '$SHARETYPE'"; exit 1;;
27 esac
1ee4335f
FF
28}
29
30PARAMS=""
bea93fbd
FF
31while getopts :ha:c:dt: option
32do
33 case "$option" in
34 h) show_usage;;
35 a) validate_share $OPTARG; PARAMS="$PARAMS --es action $OPTARG";;
36 c) PARAMS="$PARAMS --es content-type $OPTARG";;
37 d) PARAMS="$PARAMS --ez default-receiver true";;
38 t) PARAMS="$PARAMS --es title $OPTARG";;
39 ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
40 esac
1ee4335f 41done
bea93fbd 42shift $(($OPTIND-1))
1ee4335f 43
bea93fbd 44if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
1ee4335f 45
fa5ce6c4 46if [ $# != 0 ]; then
bea93fbd
FF
47 # Note that the file path can contain whitespace.
48 @TERMUX_API@ Share $PARAMS --es file "`realpath "$1"`"
fa5ce6c4 49else
bea93fbd 50 @TERMUX_API@ Share $PARAMS
fa5ce6c4 51fi