~kris/dots

srice

ref: f5fc91419850ee5f2652bdce0dcc214de18b4a22 srice/.local/bin/blog-title -rwxr-xr-x 449 bytes
f5fc9141 — Kris Yotam add wallpapermenu script (was untracked); auto-detect output so cw works on any machine 3 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