#! /usr/local/bin/zsh # # this file: # https://dataswamp.org/~incal/sth/scripts/url2title local url=${1/twitter.com/nitter.net} local last=${HOME}/last.txt if [[ $url != $(cat $last) ]]; then echo $url > $last local ua="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" local title=$(wget --user-agent=$ua \ -q \ -O - \ $url | perl -l \ -0777 \ -n \ -e 'print $1 if /\s*(.*?)\s*<\/title/si') local non_title="Index of " if [[ ${#${title#*$non_title}} < ${#${title}} ]]; then echo "directory listing, ${title#*$non_title}" else echo $title fi fi