add resume support to dwl
This commit is contained in:
@@ -240,6 +240,7 @@ change the default without having to pass flags every time.
|
|||||||
| Key | Default | Description |
|
| Key | Default | Description |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `DWL_PREFERRED_TOOL` | _(empty)_ | Force `dwl` to use `curl`, `wget`, or `fetch` (auto-detected when unset) |
|
| `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` |
|
| `MYEXTIP_DEFAULT_URL` | `https://ip-api.com/json` | API endpoint used by `myextip` |
|
||||||
|
|
||||||
**`[packages]`**
|
**`[packages]`**
|
||||||
|
|||||||
@@ -117,6 +117,10 @@ TERM=xterm-256color
|
|||||||
# Unset = auto-detect (curl preferred, then wget, then fetch).
|
# Unset = auto-detect (curl preferred, then wget, then fetch).
|
||||||
#DWL_PREFERRED_TOOL=curl
|
#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.
|
# myextip: API endpoint for external IP lookup.
|
||||||
# Alternatives: https://ipinfo.io/json, https://ip-api.com/json/
|
# Alternatives: https://ipinfo.io/json, https://ip-api.com/json/
|
||||||
#MYEXTIP_DEFAULT_URL=https://ip-api.com/json/
|
#MYEXTIP_DEFAULT_URL=https://ip-api.com/json/
|
||||||
|
|||||||
@@ -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).
|
# Supported values: curl, wget, fetch. Unset uses auto-detection (default).
|
||||||
#DWL_PREFERRED_TOOL=curl
|
#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.
|
# myextip: API endpoint URL used to retrieve external IP information.
|
||||||
# Default: https://ip-api.com/json/
|
# Default: https://ip-api.com/json/
|
||||||
# Compatible alternatives: https://ipinfo.io/json, https://ip-api.com/json/
|
# Compatible alternatives: https://ipinfo.io/json, https://ip-api.com/json/
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ version-bump.
|
|||||||
CPU, RAM) using pure Bash + `/proc`. **[medium]**
|
CPU, RAM) using pure Bash + `/proc`. **[medium]**
|
||||||
|
|
||||||
### net
|
### 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]**
|
wget for interrupted downloads; gate behind a `-r` flag. **[easy]**
|
||||||
- [ ] **`myextip` multiple providers** — fall back to a secondary URL
|
- [ ] **`myextip` multiple providers** — fall back to a secondary URL
|
||||||
(configurable via `MYEXTIP_FALLBACK_URL`) when the primary times out.
|
(configurable via `MYEXTIP_FALLBACK_URL`) when the primary times out.
|
||||||
|
|||||||
@@ -36,20 +36,29 @@
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Download a resource using curl, wget, or fetch.
|
# 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()
|
dwl()
|
||||||
{
|
{
|
||||||
local timeout=""
|
local timeout=""
|
||||||
|
local resume=0
|
||||||
|
|
||||||
|
case "${DWL_DEFAULT_RESUME,,}" in
|
||||||
|
1|true|yes|on)
|
||||||
|
resume=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Parse leading options before the URL.
|
# Parse leading options before the URL.
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--help|-h)
|
--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 "Downloads a resource using curl, wget, or fetch."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Arguments:"
|
echo "Arguments:"
|
||||||
echo " -t, --timeout Maximum time in seconds to wait for the transfer."
|
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 " url The full URL to download (http/https/ftp)."
|
||||||
echo " output_file (Optional) Path to save the file. If omitted, prints to stdout."
|
echo " output_file (Optional) Path to save the file. If omitted, prints to stdout."
|
||||||
return 0
|
return 0
|
||||||
@@ -62,6 +71,14 @@ dwl()
|
|||||||
timeout="$2"
|
timeout="$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
-r|--resume)
|
||||||
|
resume=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--no-resume)
|
||||||
|
resume=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
@@ -100,8 +117,12 @@ dwl()
|
|||||||
local args=(-sL)
|
local args=(-sL)
|
||||||
[[ -n "$timeout" ]] && args+=(--max-time "$timeout" --connect-timeout "$timeout")
|
[[ -n "$timeout" ]] && args+=(--max-time "$timeout" --connect-timeout "$timeout")
|
||||||
if [[ -z "$output" ]]; then
|
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"
|
curl "${args[@]}" "$url"
|
||||||
else
|
else
|
||||||
|
(( resume == 1 )) && args+=(-C -)
|
||||||
curl "${args[@]}" -o "$output" "$url"
|
curl "${args[@]}" -o "$output" "$url"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@@ -110,6 +131,7 @@ dwl()
|
|||||||
{
|
{
|
||||||
local args=(-q)
|
local args=(-q)
|
||||||
[[ -n "$timeout" ]] && args+=(--timeout="$timeout")
|
[[ -n "$timeout" ]] && args+=(--timeout="$timeout")
|
||||||
|
(( resume == 1 )) && args+=(-c)
|
||||||
if [[ -z "$output" ]]; then
|
if [[ -z "$output" ]]; then
|
||||||
wget "${args[@]}" -O- "$url"
|
wget "${args[@]}" -O- "$url"
|
||||||
else
|
else
|
||||||
@@ -121,6 +143,9 @@ dwl()
|
|||||||
{
|
{
|
||||||
local args=()
|
local args=()
|
||||||
[[ -n "$timeout" ]] && args+=(-T "$timeout")
|
[[ -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
|
if [[ -z "$output" ]]; then
|
||||||
fetch "${args[@]}" -o - "$url"
|
fetch "${args[@]}" -o - "$url"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user