| 1 | #!/bin/sh |
| 2 | |
| 3 | show_usage () { |
| 4 | echo "usage: termux-share [options] [file]" |
| 5 | echo "Share a file specified as argument or the stdin as text input." |
| 6 | echo "Options:" |
| 7 | echo " -a, --action which action to performed on the shared content: edit/send/view (default:view)" |
| 8 | echo " -d, --default share to the default receiver if one is selected (instead of showing a chooser)" |
| 9 | echo " -t, --title title to use for shared content (default: shared file name)" |
| 10 | echo " -c, --content-type content-type to use (default: guessed from file extension, text/plain for stdin)" |
| 11 | } |
| 12 | |
| 13 | validate_share () { |
| 14 | SHARETYPE=$1 |
| 15 | case "$SHARETYPE" in |
| 16 | edit) |
| 17 | ;; |
| 18 | send) |
| 19 | ;; |
| 20 | view) |
| 21 | ;; |
| 22 | *) |
| 23 | echo "Unsupported action: '$SHARETYPE' - only edit/send/view available" |
| 24 | exit 1 |
| 25 | ;; |
| 26 | esac |
| 27 | } |
| 28 | |
| 29 | PARAMS="" |
| 30 | O=`busybox getopt -q -l action: -l content-type: -l default -l help -l mimetype -l title: -- a:c:dht: "$@"` |
| 31 | if [ $? != 0 ] ; then show_usage; exit 1 ; fi |
| 32 | eval set -- "$O" |
| 33 | while true; do |
| 34 | case "$1" in |
| 35 | -a|--action) validate_share $2; PARAMS="$PARAMS --es action $2"; shift 2;; |
| 36 | -c|--content-type) PARAMS="$PARAMS --es content-type $2"; shift 2;; |
| 37 | -d|--default) PARAMS="$PARAMS --ez default-receiver true"; shift 1;; |
| 38 | -h|--help) show_usage; exit 0;; |
| 39 | -t|--title) PARAMS="$PARAMS --es title $2"; shift 2;; |
| 40 | --) shift; break;; |
| 41 | *) echo Error; exit 1;; |
| 42 | esac |
| 43 | done |
| 44 | |
| 45 | if [ $# -gt 1 ]; then echo "Only one file can be shared"; exit 1; fi |
| 46 | if [ $# != 0 ]; then PARAMS="$PARAMS --es file `realpath $1`"; fi |
| 47 | |
| 48 | @TERMUX_API@ Share $PARAMS |