-
Notifications
You must be signed in to change notification settings - Fork 362
/
Copy pathtermux-share.in
56 lines (49 loc) · 1.78 KB
/
termux-share.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!@TERMUX_PREFIX@/bin/sh
# shellcheck shell=bash
set -e -u
SCRIPTNAME=termux-share
show_usage () {
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
}
validate_share () {
SHARETYPE=$1
case "$SHARETYPE" in
edit) ;;
send) ;;
view) ;;
*) echo "$SCRIPTNAME: Unsupported action: '$SHARETYPE'"; exit 1;;
esac
}
PARAMS=""
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
done
shift $((OPTIND-1))
if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi
if [ $# != 0 ]; then
if [ ! -f "$1" ]; then
echo "$1 is not a file"
exit 1
fi
# Note that the file path can contain whitespace.
@TERMUX_PREFIX@/libexec/termux-api Share $PARAMS --es file "$(realpath "$1")"
else
@TERMUX_PREFIX@/libexec/termux-api Share $PARAMS
fi