~kris/dots

srice

ref: e9b48d06a8541f3eda5c4db90382ab3c77183afb srice/.local/bin/blog-title -rwxr-xr-x 449 bytes
e9b48d06 — Kris Yotam xprofile: systemd-aware pipewire start + blueman-applet; sb-internet: tolerate missing /proc/net/wireless 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