#!/bin/bash # expensiveClock -d # required: firefox, jp2a, imagemagick (just for png2jpg), timeout (coreutils) # checks command -v jp2a >/dev/null 2>&1 || { echo "I need jp2a, exiting." >&2; exit 1; } command -v convert >/dev/null 2>&1 || { echo "I need imagemagick convert, exiting." >&2; exit 1; } command -v timeout >/dev/null 2>&1 || { echo "I need timeout (coreutils), exiting." >&2; exit 1; } # analog or digital app=("$HOME/apps/firefox/firefox") if [[ "$1" == "-d" ]]; then clock="digital" else clock="analog" fi # modern firefox whereabouts # note: dev edition seems to work in wsl1 https://www.mozilla.org/en-US/firefox/all/#product-desktop-developer command -v "${app[@]}" >/dev/null 2>&1 || { echo "I need some sort of firefox, exiting." >&2; exit 1; } # clear once clear printf "\\33[?25l" # hide cursor https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 # center text custom centertext(){ columns=$(tput cols) string="$1" printf "%*s\\n" $(((${#string}+columns)/2)) "${string//R/ }" } # tmp dir http://mywiki.wooledge.org/BashFAQ/062 tmp="/tmp/$RANDOM-$$" trap '[ -n "$tmp" ] && rm -fr "$tmp"; printf "\\33[?25h"; kill %% >/dev/null 2>&1' EXIT # unhide cursor on exit mkdir -m 700 "$tmp" || { echo '!! unable to create a tmpdir' >&2; tmp=; exit 1; } # scripted svg found on web if [[ $clock == "analog" ]]; then name="$tmp/analog.svg" cat > "$name" << EOF EOF elif [[ $clock == "digital" ]]; then name="$tmp/digital.htm" cat > "$name" << EOF Clock EOF fi # main main () { timeout -v 25 "${app[@]}" --screenshot --window-size=1000,1000 "$tmp/woot.png" "file:///${name}" >/dev/null 2>&1 # just pipe if [[ $clock == "analog" ]]; then convert "$tmp/woot.png" -resize 1140\!x1000 jpg:- | jp2a -f --chars="R.xX" - > "$tmp/tmp.txt" || exit # using 'R' as a placeholder for easier centering elif [[ $clock == "digital" ]]; then convert "$tmp/woot.png" -trim -bordercolor black -border 55 +repage jpg:- | jp2a -f --chars="R.xX" - > "$tmp/tmp.txt" || exit clear fi # center printf "\\033[H" # cursor to home while read -r line ; do centertext "$line" done <"$tmp/tmp.txt" } # loop 4ever while true; do # updating each full minute main sleep $((60 - $(date +%s) % 60)) done