| 1 | #!/data/data/com.termux/files/usr/bin/sh |
| 2 | set -e -u |
| 3 | |
| 4 | SCRIPTNAME=termux-open |
| 5 | show_usage () { |
| 6 | echo "Usage: $SCRIPTNAME [options] path-or-url" |
| 7 | echo "Open a file or URL in an external app." |
| 8 | echo " --send if the file should be shared for sending" |
| 9 | echo " --view if the file should be shared for viewing (default)" |
| 10 | echo " --chooser if an app chooser should always be shown" |
| 11 | echo " --content-type type specify the content type to use" |
| 12 | exit 0 |
| 13 | } |
| 14 | |
| 15 | TEMP=`busybox getopt \ |
| 16 | -n $SCRIPTNAME \ |
| 17 | -o h \ |
| 18 | --long send,view,chooser,content-type:,help\ |
| 19 | -- "$@"` |
| 20 | eval set -- "$TEMP" |
| 21 | |
| 22 | ACTION=android.intent.action.VIEW |
| 23 | EXTRAS="" |
| 24 | while true; do |
| 25 | case "$1" in |
| 26 | --send) ACTION="android.intent.action.SEND"; shift;; |
| 27 | --view) ACTION="android.intent.action.VIEW"; shift;; |
| 28 | --chooser) EXTRAS="$EXTRAS --ez chooser true"; shift;; |
| 29 | --content-type) EXTRAS="$EXTRAS --es content-type $2"; shift 2;; |
| 30 | -h | --help) show_usage;; |
| 31 | --) shift; break ;; |
| 32 | esac |
| 33 | done |
| 34 | if [ $# != 1 ]; then |
| 35 | show_usage |
| 36 | fi |
| 37 | |
| 38 | FILE="$1" |
| 39 | if [ -f "$FILE" ]; then |
| 40 | FILE=`realpath "$FILE"` |
| 41 | fi |
| 42 | |
| 43 | am broadcast --user 0 \ |
| 44 | -a $ACTION \ |
| 45 | -n com.termux/com.termux.app.TermuxOpenReceiver \ |
| 46 | $EXTRAS \ |
| 47 | -d "$FILE" \ |
| 48 | > /dev/null |
| 49 | |