#!/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>.*/\1/p' | sed -e 's/&/\&/g' -e 's/[[:space:]]\+/ /g' -e 's/^ //' -e 's/ $//' fi