1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-09-19 14:24:07 -07:00

add URL-encoding to grab

now files with spaces work properly, yippee
This commit is contained in:
Connor Olding 2024-07-19 08:21:03 -07:00
parent 5ae0ca4302
commit 44e88ed586

14
sh/grab
View file

@ -20,6 +20,15 @@ x=${?#0}
printf "failed to %s\n" "$task" >&2
exit ${x:-1}
}
esc(){
while [ -n "$1" ]; do
case "$1" in
([\!\"$\&-\>@-~]*) printf '%.1s' "$1";;
(*) printf '%%%02X' "'$1";;
esac
set -- "${1#?}"
done
} 2>&-
get(){
if [ -f /usr/bin/curl ]
then curl -sSfLgm5 -o "$@"
@ -61,6 +70,7 @@ esac || die
touch -- "$fn" || die
will ensure supported protocols # busybox restricts this
fx="$(esc "$fn")"
case "$f" in
(http://*);;
(https://*);;
@ -70,9 +80,9 @@ case "$f" in
printf 'unsupported protocol: %s\n' "${f%%:*}" >&2
die;;
(*)
f="https://$remote/$fn";;
f="https://$remote/$fx";;
esac
g="https://$remote/$fn.minisig"
g="https://$remote/$fx.minisig"
will download "$fn" from "$f"
get "$fn" -- "$f" || die