1
0

pimp curl_htmlq

This commit is contained in:
Peder Bergebakken Sundt 2025-03-09 19:06:44 +01:00
parent efdfdde6a2
commit 16e51534f9

19
do.sh

@ -76,7 +76,24 @@ curl() (
)
curl_htmlq() {
local url="$1"; shift
curl "${curlopts[@]}" "$url" | tr '\n' ' ' | tr -s ' ' | htmlq --base "$url" "$@"
# split args before and after '--' between curl and htmlq, preferring to htmlq
local -a extra_curlopts=()
local -a htmlqopts=()
while [[ "$#" -gt 0 && "$1" != "--" ]]; do
extra_curlopts+=("$1")
shift
done
if [[ "$#" -gt 0 && "$1" == "--" ]]; then
shift
htmlqopts=("$@")
elif [[ "$#" -eq 0 ]]; then
htmlqopts=("${extra_curlopts[@]}")
extra_curlopts=()
else
die "unable to understand args: extra_curlopts=(${extra_curlopts[*]})"
fi
curl "$url" "${extra_curlopts[@]}" | tr '\n' ' ' | tr -s ' ' | htmlq --base "$url" "${htmlqopts[@]}"
}