Wcurl: a curl wrapper to download files
samueloph.dev
samueloph.dev
curl -#JLOC -
* -# Progress bar instead of the standard meter* -J Use the server-specified Content-Disposition filename instead of extracting a filename from the URL
* -L Follow redirects
* -O Write output to a local file (download)
* -C - Resume transfers
Maybe a good mnemonic would be something along the lines of jlo liking hashtags?
Can't wrap my head around how -J maps to remote header name...still, this was super useful, thanks!
Works just fine without it
$ curl -JLOC- "https://news.ycombinator.com/news.css?nZdOgS3Y18zj0ynCo50h"
curl: --continue-at and --remote-header-name cannot be combined
curl: try 'curl --help' or 'curl --manual' for more information"wcurl --opts="--progress-bar" URL"
I was wondering if that should be the default for wcurl, but the bar only works for downloading single files, I was afraid of users thinking there's a bug whenever they downloaded more than one file if the bar wasn't there anymore.
alias wcurl="curl -# -O $1"
(I just tested this on MacOS).BRB, forking curl to add email client support.
How is it silly if the identical functionality is there, but you just need to use more command-line arguments?
Until... I show them.
They become unresponsive, but their hair is removed.
Job done.
There's also some value in providing a ready-to-use wrapper for users that install the curl package. Maybe wcurl will also show up in other distributions after a while, especially since Daniel also likes the idea.
There's aria2
alias wcurl = curl -# -O $1 --location --remote-name --remote-time --retry 10 --retry-max-time 10 --continue-at -"
the main reason I use wget is because it automatically retries downloads, which is vital for my not-so-great internet, and an option I wish was on in curl by default, as half the world uses curl, and then keep trying to automatically download 400MB files, which I have trouble finishing.Then, if you look at the script, it's basically that, with some minor cleaning up and nicer error handling.
and you can use `-q` to have it exclude the curlrc and use only args you pass to it. curl has such an amazing amount of power, but also means it has a lot of options to utilize a lot of things folks take for granted (exactly like retries, ect)
Maybe even should be a shellcheck rule.
most of the time though, those options should be safe; only really need to not have auto-retries are when trying to get super accurate date (like observing odd behavior, you dont want thing to simply "auto-work" when finetuning something, or triaging an upstream-server or dns issue)
i often write my scripts execing calls like `\curl -q ...` such that i get no user's alias of curl and ensures a consistant no-config amongst my system and others (although gnu curl vs mac curl (and other binaries of gnu vs mac vs busybox) are always the real fun part). (if the user has their own bash-function of curl then its on them for knowing their system will be special compared to others and results maybe inconsistent)
--remote-name-all
otherwise you have to specify -O for every URL specified. For the same reason, remove $1 and rely on all parameters being added at the end of line. The example above will only download the first URL.(I personally think this should have been the default from the beginning, -O should have set the behaviour for all following parameters until changed, but that is too late to change now.)
There is also --remote-header-name (-J) which takes the remote file name from the header instead of the URL, which is what wget does.
I don't think that's the case, that behavior is opt-in as indicated in wget's manpage:
> This can currently result in extra round-trips to the server for a "HEAD" request, and is known to suffer from a few bugs, which is why it is not currently enabled by default.
It must be relatively recent because old those old answers do not mention it : https://stackoverflow.com/questions/7131670/make-a-bash-alia... https://stackoverflow.com/questions/34340575/zsh-alias-with-...
On the other hand I tested it in both bash and zsh, and it works in both
Note: wcurl sets a bit more flags than that, it also encodes the whitespaces in the URL and does parallel downloading of multiple URLs.
Sadly I can’t since it is dependent upon the util-linux version of getopt which means it fails on bsd and macOS systems. Understandable since it is always available on the specific target the script was written for and it does make life easier.
I knew getopt was linux-specific but I thoughts the only impact was that the long form argument (--opt) would not work. I turns out it doesn't run at all instead.
We should be able to fix this within the next few days, thank you!
It's fixed now, should work in non-linux environments.
Personally I never had any problems using curl to download files, nor remembering tar arguments.
To a senior, tools like this make no sense, because they're unnecessary, and contribute to bloat and waste, both for systems, and for the time spent.
But then again, this is the same industry that thinks shipping 600 MB of Node packages and an entire instance of Chromium is what it takes to use ffmpeg, so, I'm not surprised, just disappointed.