From 12d3fff0479ac0e56b1843e5f1d9fbfdc10a2c61 Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Tue, 28 Feb 2017 00:15:22 +0100 Subject: [PATCH] termux-tools: Add termux-open --- packages/termux-tools/termux-open | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 packages/termux-tools/termux-open diff --git a/packages/termux-tools/termux-open b/packages/termux-tools/termux-open new file mode 100755 index 000000000..aaa7bd048 --- /dev/null +++ b/packages/termux-tools/termux-open @@ -0,0 +1,44 @@ +#!/data/data/com.termux/files/usr/bin/sh +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 \ + --long send,view,chooser,content-type:,\ + -- "$@"` +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 + +am broadcast --user 0 \ + -a $ACTION \ + -n com.termux/com.termux.app.TermuxOpenReceiver \ + $EXTRAS \ + -d "$1" \ + > /dev/null +