~kris/dots

srice

ref: e98f3b030dc24445bd55c68d95d2d81933fd68b3 srice/.local/bin/blog-title -rw-r--r-- 449 bytes
e98f3b03 — Kris Yotam chore: sync local state after restore (push updates, no pull) a month 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