aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-06-18 13:47:09 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-06-18 13:47:09 +1200
commite773de571cbeae5389c39d6b2d3733d8a10c5b1c (patch)
treee7de3c2cda9d4509620730e9ba99571a9f1f4831 /bin
parentFix wrapping (diff)
downloaddotfiles-e773de571cbeae5389c39d6b2d3733d8a10c5b1c.tar.gz
dotfiles-e773de571cbeae5389c39d6b2d3733d8a10c5b1c.zip
Add htmlurls, mdurls, urlcheck
No manual pages for these yet
Diffstat (limited to 'bin')
-rwxr-xr-xbin/htmlurls6
-rwxr-xr-xbin/mdurls4
-rwxr-xr-xbin/urlcheck34
3 files changed, 44 insertions, 0 deletions
diff --git a/bin/htmlurls b/bin/htmlurls
new file mode 100755
index 00000000..b99667de
--- /dev/null
+++ b/bin/htmlurls
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+hash pup || exit
+cat -- "${@:-/dev/stdin}" | ## shellcheck disable=SC2002
+pup 'a attr{href}' |
+LANG=C.UTF-8 sort | # skipping punctuation in a locale sort is unacceptable
+uniq
diff --git a/bin/mdurls b/bin/mdurls
new file mode 100755
index 00000000..e135101f
--- /dev/null
+++ b/bin/mdurls
@@ -0,0 +1,4 @@
+#!/usr/bin/env bash
+hash markdown htmlurls || exit
+markdown "$@" |
+htmlurls
diff --git a/bin/urlcheck b/bin/urlcheck
new file mode 100755
index 00000000..5f586aff
--- /dev/null
+++ b/bin/urlcheck
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+self=urlcheck
+tm=${URLCHECK_TIMEOUT:-8}
+shopt -s extglob
+declare -a copts
+declare -i ex
+head=$(mktemp) || exit
+body=$(mktemp) || exit
+cleanup() {
+ rm -f -- "$head" "$body"
+}
+trap cleanup EXIT
+while read -r url ; do
+ [[ $url == 'http'* ]] || continue
+ if ! curl -fHLsS -D "$head" -m "$tm" -o "$body" "$url" ; then
+ printf '%s: %s raises error\n' \
+ "$self" "$url" >&2
+ continue
+ fi
+ while IFS=': ' read -r header value ; do
+ [[ $header == 'Location' ]] || continue
+ printf '%s: %s redirects to %s\n' \
+ "$self" "$url" "$value" >&2
+ break
+ done < "$head"
+ [[ $url == 'http:'* ]] || continue
+ securl=${url/http:/https:}
+ if curl -fLsS -m "$tm" -o /dev/null -- "$securl" 2>/dev/null ; then
+ printf '%s: %s has a working secure version at %s\n' \
+ "$self" "$url" "$securl" >&2
+ ((ex++))
+ fi
+done
+exit "$((ex > 0))"