~kris/dots

srice

ref: b42b72dc2648499470b89418ac629e40f41d3149 srice/.local/bin/blog-title -rwxr-xr-x 449 bytes
b42b72dc — Kris Yotam sb-battery: match macsmc-battery by type, add low-battery dunst alerts; xprofile: caps:super 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