diff --git a/README.md b/README.md index f4eb167..1ab602e 100644 --- a/README.md +++ b/README.md @@ -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]`** diff --git a/doc/profile.conf.example b/doc/profile.conf.example index 61d6606..d21e707 100755 --- a/doc/profile.conf.example +++ b/doc/profile.conf.example @@ -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/ diff --git a/doc/profile.conf.fatalerrors b/doc/profile.conf.fatalerrors index d1c9e99..5ef7d30 100755 --- a/doc/profile.conf.fatalerrors +++ b/doc/profile.conf.fatalerrors @@ -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/ diff --git a/doc/todo.md b/doc/todo.md index a876302..7981a94 100755 --- a/doc/todo.md +++ b/doc/todo.md @@ -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. diff --git a/profile.d/net.sh b/profile.d/net.sh index 846dd6e..efd8b00 100644 --- a/profile.d/net.sh +++ b/profile.d/net.sh @@ -36,20 +36,29 @@ # ------------------------------------------------------------------------------ # Download a resource using curl, wget, or fetch. -# Usage: dwl [-t ] [output_file] +# Usage: dwl [-t ] [-r|--resume] [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 |--timeout ] [output_file]" + echo "Usage: dwl [-t |--timeout ] [-r|--resume] [--no-resume] [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