dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit c225e5561c37ff78fcb735470db0c00063e7fe53
parent a26c8117b8945f8fbc7f032c664ae8e37362a646
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri,  3 Apr 2020 19:18:01 +0200

Show alt text for smbc and xkcd

Diffstat:
M.local/bin/comic | 31++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/.local/bin/comic b/.local/bin/comic @@ -3,27 +3,36 @@ set -eu url="${1:-https://www.smbc-comics.com/}" +alttext="" case "$url" in *smbc*) - f="$(curl --write-out "%{filename_effective}\n" -OL \ - $(curl -L "$url" | \ - grep '.png' | sed 1q | sed 's/^.*https/https/;s/".*$//'))";; + html="$(curl -s -L "$url")" + f="$(curl -s --write-out "%{filename_effective}\n" -OL \ + $(printf '%s' "$html" | \ + grep '.png' | head -1 | \ + sed 's/^.*https/https/;s/".*$//'))" + alttext="$(printf '%s' "$html" | grep title | tail -1 | head -1 | \ + sed 's/.*title="//;s/".*//')";; *jspowerhour*) + html="$(curl -s -L "$url")" f="$(curl -s --write-out "%{filename_effective}\n" -OL \ - $(curl -s -L "$url" | \ - grep '.png' | sed 1q | sed 's/^.*src="//;s/" .*//;s|^|https:|'))";; + $(printf '%s' "$html" | \ + grep '.png' | head -1 | \ + sed 's/^.*src="//;s/" .*//;s|^|https:|'))";; *xkcd*) + html="$(curl -s -L "$url")" f="$(curl -s --write-out "%{filename_effective}\n" -OL \ - $(curl -s -L "$url" | \ - grep 'Image URL' | sed 1q | sed 's/^.*https/https/;s/".*$//'))" - notify-send 'xkcd' \ - "$(curl -s -L "$url" | grep 2x | sed 's/.*title="//;s/".*//' | \ - w3m -dump -T text/html )";; + $(printf '%s' "$html" | grep 'Image URL' | head -1 | \ + sed 's/^.*https/https/;s/".*$//'))" + alttext="$(printf '%s' "$html" | grep 2x | \ + sed 's/.*title="//;s/".*//')";; *) (>&2 echo "unknown site") - return 1;; + exit 1;; esac xdg-open "$f" +[ ! -z "$alttext" ] && \ + notify-send "${0##*/}" "$(printf '%s' "$alttext" | w3m -dump -T text/html)" sleep 1 rm "$f"