config

OpenBSD system configuration
git clone git://jacobedwards.org/config
Log | Files | Refs | README

commit c1e3491b4fcca736b82cfe39653d2372f694bcb6
parent 0918e0204f1d4a6f8d6ba92cd43a0ad1925ea623
Author: Jacob R. Edwards <n/a>
Date:   Sat,  5 Feb 2022 11:40:50 -0800

Improve output filenames in dl script

Filenames are now generated by decoding the basename of the url and
running it through the cleanpath script.

With the way it's written now, curl(1) could be replaced by any URL
fetching utility, such as hget(1).

Diffstat:
Mlocal/bin/bin/dl | 26++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/local/bin/bin/dl b/local/bin/bin/dl @@ -1,6 +1,24 @@ -#!/bin/sh -# Copyright 2021 Jacob R. Edwards +#!/usr/local/plan9/bin/rc +# Copyright 2021, 2022 Jacob R. Edwards # License: GPLv3 -# Write given resources to their basenames using curl(1) +# Download files specified by URLs to their basename, decoded, and +# cleaned -curl -SsL -$(jot -b O | tr -d '\n') "$@" +fn download { + if (test -e $2) + curl -SsL -^(z o)^$2 $1 + if not + curl -SsL -o $2 $1 + printf '%s (%s)\n' $1 $2 +} + +ifs=' +' +names = `{ + printf '%s\n' $* | awk -F / '{ print $NF }' | \ + urldecode | cleanpath | tr -d / +} + +for (i in `{ jot $#* }) + download $*($i) $names($i) & +wait