2019-09-19 22:41:31 +02:00
|
|
|
#!/bin/sh
|
2017-02-28 00:15:22 +01:00
|
|
|
set -e -u
|
|
|
|
|
|
|
|
SCRIPTNAME=termux-open
|
|
|
|
show_usage () {
|
|
|
|
echo "Usage: $SCRIPTNAME [options] path-or-url"
|
|
|
|
echo "Open a file or URL in an external app."
|
|
|
|
echo " --send if the file should be shared for sending"
|
|
|
|
echo " --view if the file should be shared for viewing (default)"
|
|
|
|
echo " --chooser if an app chooser should always be shown"
|
|
|
|
echo " --content-type type specify the content type to use"
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
TEMP=`busybox getopt \
|
|
|
|
-n $SCRIPTNAME \
|
|
|
|
-o h \
|
2017-03-01 17:20:37 +01:00
|
|
|
--long send,view,chooser,content-type:,help\
|
2017-02-28 00:15:22 +01:00
|
|
|
-- "$@"`
|
|
|
|
eval set -- "$TEMP"
|
|
|
|
|
|
|
|
ACTION=android.intent.action.VIEW
|
|
|
|
EXTRAS=""
|
|
|
|
while true; do
|
|
|
|
case "$1" in
|
|
|
|
--send) ACTION="android.intent.action.SEND"; shift;;
|
|
|
|
--view) ACTION="android.intent.action.VIEW"; shift;;
|
|
|
|
--chooser) EXTRAS="$EXTRAS --ez chooser true"; shift;;
|
|
|
|
--content-type) EXTRAS="$EXTRAS --es content-type $2"; shift 2;;
|
|
|
|
-h | --help) show_usage;;
|
|
|
|
--) shift; break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
if [ $# != 1 ]; then
|
|
|
|
show_usage
|
|
|
|
fi
|
|
|
|
|
2017-02-28 00:29:49 +01:00
|
|
|
FILE="$1"
|
|
|
|
if [ -f "$FILE" ]; then
|
2019-02-12 04:15:39 +01:00
|
|
|
FILE=$(realpath "$FILE")
|
2017-02-28 00:29:49 +01:00
|
|
|
fi
|
|
|
|
|
2017-02-28 00:15:22 +01:00
|
|
|
am broadcast --user 0 \
|
|
|
|
-a $ACTION \
|
|
|
|
-n com.termux/com.termux.app.TermuxOpenReceiver \
|
|
|
|
$EXTRAS \
|
2017-02-28 00:29:49 +01:00
|
|
|
-d "$FILE" \
|
2017-02-28 00:15:22 +01:00
|
|
|
> /dev/null
|
|
|
|
|