Skip to content

Instantly share code, notes, and snippets.

@serrasqueiro
Last active January 1, 2026 14:12
Show Gist options
  • Select an option

  • Save serrasqueiro/88d6576dc3860b19a39854e96b875ecc to your computer and use it in GitHub Desktop.

Select an option

Save serrasqueiro/88d6576dc3860b19a39854e96b875ecc to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Elegant digital clock
usage ()
{
echo "Usage: $0 [-h|--help] [-w|--what]"; echo
echo "Launches an elegant digital xclock.
-w shows what font is the best, and what is used as default font."
exit 0
}
dig_clock ()
{
local FNT="$*"
local SIZE=28
local FACE="${FNT}-${SIZE}"
# Check for the font
if ! fc-list | grep -qi "$FNT"; then
echo "Warning: '$FNT' not found in fontconfig."
echo
fc-list | grep Mono:
fi
xclock \
-digital \
-strftime "%a %H:%M:%S" \
-face "$FACE" \
-update 1 \
-padding 20 \
-geometry 320x80 &
}
best_font ()
{
local candidates=(
"Bitstream Vera Sans Mono"
"DejaVu Sans Mono"
"Liberation Mono"
"Noto Sans Mono"
"JetBrains Mono"
"Fira Mono"
"Monospace"
)
for font in "${candidates[@]}"; do
if fc-list | grep -qi "$font"; then
echo "$font"
return 0
fi
done
# Fallback
echo "Monospace"
return 0
}
#
# Main script
#
FNT="Bitstream Vera Sans Mono"
case $1 in
-h|--help) usage;;
-w|--what)
echo "Default font is: $FNT"
echo
[ "$(best_font)" == "$FNT" ] && echo -n "(Matches) "
echo "Best font: $(best_font)"
exit 0
;;
[A-Z]*) echo "$@:::"; dig_clock "$@"; exit 0;;
esac
dig_clock "$FNT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment