From 750c606e2f78f15bc394498c591b6b142fe872da Mon Sep 17 00:00:00 2001 From: Ronald Y <46513942+knyipab@users.noreply.github.com> Date: Sun, 13 Mar 2022 21:45:55 +0800 Subject: [PATCH 1/2] more features for StorageGetAPI: print URI, async, folder, persistable, etc. --- scripts/termux-storage-get.in | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/scripts/termux-storage-get.in b/scripts/termux-storage-get.in index 86b236e..b80f1e2 100644 --- a/scripts/termux-storage-get.in +++ b/scripts/termux-storage-get.in @@ -3,22 +3,47 @@ set -e -u SCRIPTNAME=termux-storage-get show_usage () { - echo "Usage: $SCRIPTNAME output-file" - echo "Request a file from the system and output it to the specified file." + echo "Usage: $SCRIPTNAME [-a] [-m] [-l] [-p] [-t mimeType] [output-file]" + echo " Request a file from the system (and output it to the specified file)." + echo "" + echo "Usage: $SCRIPTNAME -a -f [-l] [-p]" + echo " Request a folder and print URI" + echo "" + echo " -a asyncronous call (wait until finish) and print URI result" + echo " -m allow to select multiple files" + echo " -l print line(s) of URI instead of json" + echo " -t mimeType MIME type of file to open" + echo " -f pick a folder instead of file" + echo " -p persistable (persist after rebbot) permission grant" + echo " output-file output name, use pattern like %d when -m is present" exit 0 } +async=false +multiple=false +json=true +mimeType='*/*' +folder=false +persist=false -while getopts :h option +while getopts :hamlt:fp option do case "$option" in h) show_usage;; + a) async=true;; + m) multiple=true;; + l) json=false;; + t) mimeType="$OPTARG";; + f) folder=true;; + p) persist=true;; ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; esac done shift $((OPTIND-1)) +filename="" if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi -if [ $# -lt 1 ]; then echo "$SCRIPTNAME: no output file specified"; exit 1; fi +if [ "$folder" = "true" ] && [ $# -eq 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi +if [ $# -eq 1 ]; then filename="$(realpath "$1")"; fi -@TERMUX_PREFIX@/libexec/termux-api StorageGet --es file "$(realpath "$1")" +@TERMUX_PREFIX@/libexec/termux-api StorageGet --es file "$filename" --ez async "$async" --ez multiple "$multiple" --ez json "$json" --es type "$mimeType" --ez folder "$folder" --ez persist "$persist" From 6fe4a057b9592c51f6bff13037d7aaf17c62e2bf Mon Sep 17 00:00:00 2001 From: Ronald Y <46513942+knyipab@users.noreply.github.com> Date: Sun, 13 Mar 2022 22:11:19 +0800 Subject: [PATCH 2/2] fix wording --- scripts/termux-storage-get.in | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/termux-storage-get.in b/scripts/termux-storage-get.in index b80f1e2..7995206 100644 --- a/scripts/termux-storage-get.in +++ b/scripts/termux-storage-get.in @@ -3,13 +3,13 @@ set -e -u SCRIPTNAME=termux-storage-get show_usage () { - echo "Usage: $SCRIPTNAME [-a] [-m] [-l] [-p] [-t mimeType] [output-file]" + echo "Usage: $SCRIPTNAME [-w] [-m] [-l] [-p] [-t mimeType] [output-file]" echo " Request a file from the system (and output it to the specified file)." echo "" - echo "Usage: $SCRIPTNAME -a -f [-l] [-p]" + echo "Usage: $SCRIPTNAME -w -f [-l] [-p]" echo " Request a folder and print URI" echo "" - echo " -a asyncronous call (wait until finish) and print URI result" + echo " -w wait/block until finish (synchronous call) and print URI result" echo " -m allow to select multiple files" echo " -l print line(s) of URI instead of json" echo " -t mimeType MIME type of file to open" @@ -19,18 +19,18 @@ show_usage () { exit 0 } -async=false +wait=false multiple=false json=true mimeType='*/*' folder=false persist=false -while getopts :hamlt:fp option +while getopts :hwmlt:fp option do case "$option" in h) show_usage;; - a) async=true;; + w) wait=true;; m) multiple=true;; l) json=false;; t) mimeType="$OPTARG";; @@ -46,4 +46,4 @@ if [ $# -gt 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi if [ "$folder" = "true" ] && [ $# -eq 1 ]; then echo "$SCRIPTNAME: too many arguments"; exit 1; fi if [ $# -eq 1 ]; then filename="$(realpath "$1")"; fi -@TERMUX_PREFIX@/libexec/termux-api StorageGet --es file "$filename" --ez async "$async" --ez multiple "$multiple" --ez json "$json" --es type "$mimeType" --ez folder "$folder" --ez persist "$persist" +@TERMUX_PREFIX@/libexec/termux-api StorageGet --es file "$filename" --ez wait "$wait" --ez multiple "$multiple" --ez json "$json" --es type "$mimeType" --ez folder "$folder" --ez persist "$persist"