aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-05-12 14:59:22 +1200
committerTom Ryder <tom@sanctum.geek.nz>2020-05-12 14:59:22 +1200
commit30883b70ad9e7ebf06b75f7e63b7b2205052a2d9 (patch)
tree4dacd15ff60a8861e97174b68f923aafac4c4d01 /bin
parentAdd an idea about urlmt(1df) (diff)
downloaddotfiles-30883b70ad9e7ebf06b75f7e63b7b2205052a2d9.tar.gz
dotfiles-30883b70ad9e7ebf06b75f7e63b7b2205052a2d9.zip
Use `curl -w` for getting media type
Much nicer.
Diffstat (limited to 'bin')
-rw-r--r--bin/urlmt.sh16
1 files changed, 9 insertions, 7 deletions
diff --git a/bin/urlmt.sh b/bin/urlmt.sh
index cd71b0fd..69bef5f7 100644
--- a/bin/urlmt.sh
+++ b/bin/urlmt.sh
@@ -1,8 +1,10 @@
# Get the MIME type for a given URL
-urlh "$1" Content-Type |
-
-# Use last line only, remove any charset suffix
-sed '
-$!d
-s/;.*//
-'
+self=urlmt
+if [ "$#" -ne 1 ] || [ -z "$1" ] ; then
+ printf >&2 '%s: Need a single URL\n' \
+ "$self"
+ exit 2
+fi
+url=$1
+curl --head --output /dev/null --write-out '%{content_type}\n' "$url" |
+ awk -F\; '{print $1}'