#!/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