diff --git a/scripts/termux-storage-get.in b/scripts/termux-storage-get.in index 86b236e..7995206 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 [-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 -w -f [-l] [-p]" + echo " Request a folder and print URI" + echo "" + 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" + 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 } +wait=false +multiple=false +json=true +mimeType='*/*' +folder=false +persist=false -while getopts :h option +while getopts :hwmlt:fp option do case "$option" in h) show_usage;; + w) wait=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 wait "$wait" --ez multiple "$multiple" --ez json "$json" --es type "$mimeType" --ez folder "$folder" --ez persist "$persist"