commit 2b1c39973da1f5ba2ae4b30bada8f312947ac05a parent 667f27e98e23570e8f6e6beba3ffb4dc4fe474f9 Author: hhvn <dev@hhvn.uk> Date: Thu, 8 Jul 2021 00:27:16 +0100 .s/b/netdownload: integrate with new plumbing setup Also, handle download files better, reverse it to avoid massive tab-completion steps. Diffstat:
M | .scripts/bin/netdownload | | | 36 | +++++++++++++++++++++++++++++------- |
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/.scripts/bin/netdownload b/.scripts/bin/netdownload @@ -1,15 +1,37 @@ #!/bin/sh -input=$(printf "no\nyes\n" | dmenu -i -p "Download: $1") -[ "$input" = "yes" ] && { - file="$HOME/general/downloads/$(echo "$1" | tr '/' '+')" +# silently ignore non-authorative (or non-) uris. +echo "$1" | grep "://" >/dev/null || exit 99 + +uri2file(){ + awk ' + BEGIN { + FS="/" + } + + { + for (i=NF; i != 1; i--) + printf "%s+", $i + printf "%s\n", $1 + }' +} + +input=$(printf "plumb\ndownload\n" | dmenu -i -p "$1") +case "$input" in +d*) + file="$HOME/general/downloads/$(echo "$1" | uri2file)" while [ -f $file ] do file="$HOME/general/downloads/$(base64 </dev/urandom | tr '/' '+' | head -c10)" done curl "$(echo "$1" | sed -E 's/]|\[|}|\{/\\&/g')" > "$file" herbe "Saved to: $file" - exit 1 -} || { - urlhand2 "$1" -} + echo "$file" | xclip + ;; +p*) + plumb "$1" + ;; +*) + exit 99 + ;; +esac