Skip to content

Storage get enhanced #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions scripts/termux-storage-get.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"