aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-14 14:25:10 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-14 14:25:10 +1200
commitf10421a52b3c11e2adbdbd36d87095cab676e656 (patch)
treef357d00241aff885f515d982c51756fb3754c9ee /bin
parentFix typo (diff)
downloaddotfiles-f10421a52b3c11e2adbdbd36d87095cab676e656.tar.gz
dotfiles-f10421a52b3c11e2adbdbd36d87095cab676e656.zip
Add urlh(1) and urlmt(1)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/urlh27
-rwxr-xr-xbin/urlmt3
2 files changed, 30 insertions, 0 deletions
diff --git a/bin/urlh b/bin/urlh
new file mode 100755
index 00000000..a9ea93fd
--- /dev/null
+++ b/bin/urlh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# Get values for HTTP headers for the given URL
+
+# Check arguments
+if [ "$#" -ne 2 ] ; then
+ printf 'urlt: Need an URL and a header name\n'
+ exit 2
+fi
+url=$1 header=$2
+
+# Run cURL header request
+curl -I -- "$url" |
+
+# Unfold the headers
+unf |
+
+# Use awk to find any values for the header case-insensitively
+awk -v header="$header" '
+BEGIN {
+ FS=": *"
+ header = tolower(header)
+}
+tolower($1) == header {
+ sub(/^[^ ]*: */, "")
+ print
+}
+'
diff --git a/bin/urlmt b/bin/urlmt
new file mode 100755
index 00000000..465ff588
--- /dev/null
+++ b/bin/urlmt
@@ -0,0 +1,3 @@
+#!/bin/sh
+# Get the MIME type for a given URL
+urlh "$1" Content-Type | sed 's/; .*//'