~kris/dots

srice

ref: 178c9a25a484ead715392d50e21d03df486b8b41 srice/.local/bin/blog-title -rwxr-xr-x 449 bytes
178c9a25 — Kris Yotam conky: sync proper config from moirai (was the greenred variant) 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env sh
set -eu

if [ "$#" -ne 1 ]; then
  printf 'usage: blog-title URL\n' >&2
  exit 2
fi

url=$1
if command -v pup >/dev/null 2>&1; then
  curl -Lfs --max-time 20 "$url" | pup 'title text{}' | sed -e 's/[[:space:]]\+/ /g' -e 's/^ //' -e 's/ $//'
else
  curl -Lfs --max-time 20 "$url" |
    tr '\n' ' ' |
    sed -n 's/.*<title[^>]*>\(.*\)<\/title>.*/\1/p' |
    sed -e 's/&amp;/\&/g' -e 's/[[:space:]]\+/ /g' -e 's/^ //' -e 's/ $//'
fi