summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2015-10-20 13:25:19 +0100
committerLuke Bratch <luke@bratch.co.uk>2015-10-20 13:25:19 +0100
commitdc3c282e6c89f867e1d23ad702d3ab1703482ed0 (patch)
tree355f39b03e446096b73e26b5df67972a1b1c8ed1
parentd2a3892e23cd34c2236e54879bd850e3b70d0823 (diff)
If Content-Type is text/plain, just use the first line as the title
-rwxr-xr-xtitle.bash8
1 files changed, 7 insertions, 1 deletions
diff --git a/title.bash b/title.bash
index 7b917ac..4a83aa7 100755
--- a/title.bash
+++ b/title.bash
@@ -39,6 +39,12 @@ then
else
eval curl $OPTS -D /tmp/$TIME.header '$url' -o /tmp/$TIME.body.gz
grep -q "Content-Encoding: gzip" /tmp/$TIME.header && gunzip /tmp/$TIME.body.gz || mv /tmp/$TIME.body.gz /tmp/$TIME.body
- awk -vRS="</title>" '/<title>/{gsub(/.*<title>|\n+/,"");print;exit}' IGNORECASE=1 /tmp/$TIME.body | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//'
+ grep -q "Content-Type: text/plain" /tmp/$TIME.header && TYPE="text/plain"
+ if [ "$TYPE" == "text/plain" ]
+ then
+ head -n1 /tmp/$TIME.body
+ else
+ awk -vRS="</title>" '/<title>/{gsub(/.*<title>|\n+/,"");print;exit}' IGNORECASE=1 /tmp/$TIME.body | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//'
+ fi
rm /tmp/$TIME.header /tmp/$TIME.body
fi