add resume support to dwl

This commit is contained in:
fatalerrors
2026-05-20 16:28:32 +02:00
parent 8bfb3272c0
commit 5f8800ab44
5 changed files with 37 additions and 3 deletions

View File

@@ -240,6 +240,7 @@ change the default without having to pass flags every time.
| Key | Default | Description |
|---|---|---|
| `DWL_PREFERRED_TOOL` | _(empty)_ | Force `dwl` to use `curl`, `wget`, or `fetch` (auto-detected when unset) |
| `DWL_DEFAULT_RESUME` | `0` | Enable `dwl` resume mode by default (`1`/`true`/`yes`/`on`); applies to file downloads |
| `MYEXTIP_DEFAULT_URL` | `https://ip-api.com/json` | API endpoint used by `myextip` |
**`[packages]`**

View File

@@ -117,6 +117,10 @@ TERM=xterm-256color
# Unset = auto-detect (curl preferred, then wget, then fetch).
#DWL_PREFERRED_TOOL=curl
# dwl: Enable resume mode by default (supports curl/wget file downloads).
# Values accepted: 1/0, true/false, yes/no, on/off.
#DWL_DEFAULT_RESUME=0
# myextip: API endpoint for external IP lookup.
# Alternatives: https://ipinfo.io/json, https://ip-api.com/json/
#MYEXTIP_DEFAULT_URL=https://ip-api.com/json/

View File

@@ -91,6 +91,10 @@ SET_LOCALE="fr:fr_FR.UTF-8,us:en_US.UTF-8"
# Supported values: curl, wget, fetch. Unset uses auto-detection (default).
#DWL_PREFERRED_TOOL=curl
# dwl: Enable resume mode by default (supports curl/wget file downloads).
# Accepted values: 1/0, true/false, yes/no, on/off.
#DWL_DEFAULT_RESUME=0
# myextip: API endpoint URL used to retrieve external IP information.
# Default: https://ip-api.com/json/
# Compatible alternatives: https://ipinfo.io/json, https://ip-api.com/json/

View File

@@ -64,7 +64,7 @@ version-bump.
CPU, RAM) using pure Bash + `/proc`. **[medium]**
### net
- [ ] **`dwl` resume support** — pass `-C -` to curl / `--continue-at -` to
- [X] **`dwl` resume support** — pass `-C -` to curl / `--continue-at -` to
wget for interrupted downloads; gate behind a `-r` flag. **[easy]**
- [ ] **`myextip` multiple providers** — fall back to a secondary URL
(configurable via `MYEXTIP_FALLBACK_URL`) when the primary times out.

View File

@@ -36,20 +36,29 @@
# ------------------------------------------------------------------------------
# Download a resource using curl, wget, or fetch.
# Usage: dwl [-t <seconds>] <url> [output_file]
# Usage: dwl [-t <seconds>] [-r|--resume] <url> [output_file]
dwl()
{
local timeout=""
local resume=0
case "${DWL_DEFAULT_RESUME,,}" in
1|true|yes|on)
resume=1
;;
esac
# Parse leading options before the URL.
while [[ $# -gt 0 ]]; do
case "$1" in
--help|-h)
echo "Usage: dwl [-t <seconds>|--timeout <seconds>] <url> [output_file]"
echo "Usage: dwl [-t <seconds>|--timeout <seconds>] [-r|--resume] [--no-resume] <url> [output_file]"
echo "Downloads a resource using curl, wget, or fetch."
echo ""
echo "Arguments:"
echo " -t, --timeout Maximum time in seconds to wait for the transfer."
echo " -r, --resume Resume an interrupted download when possible (file output only)."
echo " --no-resume Disable resume mode even if enabled in config."
echo " url The full URL to download (http/https/ftp)."
echo " output_file (Optional) Path to save the file. If omitted, prints to stdout."
return 0
@@ -62,6 +71,14 @@ dwl()
timeout="$2"
shift 2
;;
-r|--resume)
resume=1
shift
;;
--no-resume)
resume=0
shift
;;
--)
shift
break
@@ -100,8 +117,12 @@ dwl()
local args=(-sL)
[[ -n "$timeout" ]] && args+=(--max-time "$timeout" --connect-timeout "$timeout")
if [[ -z "$output" ]]; then
if (( resume == 1 )); then
echo "Warning: --resume requires an output file; ignoring resume mode for stdout." >&2
fi
curl "${args[@]}" "$url"
else
(( resume == 1 )) && args+=(-C -)
curl "${args[@]}" -o "$output" "$url"
fi
}
@@ -110,6 +131,7 @@ dwl()
{
local args=(-q)
[[ -n "$timeout" ]] && args+=(--timeout="$timeout")
(( resume == 1 )) && args+=(-c)
if [[ -z "$output" ]]; then
wget "${args[@]}" -O- "$url"
else
@@ -121,6 +143,9 @@ dwl()
{
local args=()
[[ -n "$timeout" ]] && args+=(-T "$timeout")
if (( resume == 1 )); then
echo "Warning: resume mode is not supported with fetch; continuing without resume." >&2
fi
if [[ -z "$output" ]]; then
fetch "${args[@]}" -o - "$url"
else