summaryrefslogtreecommitdiff
path: root/title.bash
diff options
context:
space:
mode:
Diffstat (limited to 'title.bash')
-rwxr-xr-xtitle.bash11
1 files changed, 9 insertions, 2 deletions
diff --git a/title.bash b/title.bash
index 9bed0c5..7a44ca3 100755
--- a/title.bash
+++ b/title.bash
@@ -12,6 +12,7 @@
# v0.8 : strip newlines and leading whitespace from "broken" titles
: update user agent string
# v0.8.1: change name in version string to "blatitle"
+# v0.9 : add support for gzip compression
OPTS='--location --insecure --silent --max-filesize 1048576 --max-time 10 -A "Mozilla/5.0 (X11; Linux x86_64; rv:36.0) Gecko/20100101 Firefox/36.0"'
@@ -22,7 +23,13 @@ then
echo "Usage: '!title <url>' where <url> is an http:// or https:// URL"
elif [ "$url" == "-v" ] || [ "$url" == "--version" ]
then
- echo "blatitle version 0.8.1"
+ echo "blatitle version 0.9"
else
- curl $OPTS "$url" | sed -n -e 'H;${x;s!.*<head[^>]*>\(.*\)</head>.*!\1!I;tnext};b;:next;s!.*<title>\(.*\)</title>.*!\1!pI' | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//'
+ curl -I -H "Accept-Encoding: gzip" $OPTS "$url" | grep -q "Content-Encoding: gzip"
+ if [ "$?" == 0 ]
+ then
+ OPTS+=' -H "Accept-Encoding: gzip"'
+ GZIP="| gunzip"
+ fi
+ eval curl $OPTS "$url" $GZIP | sed -n -e 'H;${x;s!.*<head[^>]*>\(.*\)</head>.*!\1!I;tnext};b;:next;s!.*<title>\(.*\)</title>.*!\1!pI' | sed ':a;N;$!ba;s/\n//g' | sed -e 's/^[ \t]*//'
fi