Skip to content

Instantly share code, notes, and snippets.

@ruario
Last active December 12, 2022 20:15
Show Gist options
  • Save ruario/4ac6cc6086f830a836dfc6242574ca9b to your computer and use it in GitHub Desktop.
Save ruario/4ac6cc6086f830a836dfc6242574ca9b to your computer and use it in GitHub Desktop.
Prints the time in binary using emojis
#!/bin/sh -eu
# Edit to represent you timezone or comment out if you do not want to define this
YOUR_LOCATION="πŸ‡³πŸ‡΄"
# If you cannot think of anything you could use these unicode characters to represent
# military time zones.
#
# https://en.wikipedia.org/wiki/List_of_military_time_zones
#
# πŸ…° or β’Ά = UTC+1
# πŸ…± or β’· = UTC+2
# πŸ…² or β’Έ = UTC+3
# πŸ…³ or β’Ή = UTC+4
# πŸ…΄ or β’Ί = UTC+5
# πŸ…΅ or β’» = UTC+6
# πŸ…Ά or β’Ό = UTC+7
# πŸ…· or β’½ = UTC+8
# πŸ…Έ or β’Ύ = UTC+9
# πŸ…Ί or β“€ = UTC+10
# πŸ…» or Ⓛ = UTC+11
# πŸ…Ό or β“‚ = UTC+12
# πŸ…½ or Ⓝ = UTCβˆ’1
# πŸ…Ύ or β“„ = UTCβˆ’2
# πŸ…Ώ or β“… = UTCβˆ’3
# πŸ†€ or Ⓠ = UTCβˆ’4
# πŸ† or Ⓡ = UTCβˆ’5
# πŸ†‚ or β“ˆ = UTCβˆ’6
# πŸ†ƒ or Ⓣ = UTCβˆ’7
# πŸ†„ or β“Š = UTCβˆ’8
# πŸ†… or β“‹ = UTCβˆ’9
# πŸ†† or β“Œ = UTCβˆ’10
# πŸ†‡ or Ⓧ = UTCβˆ’11
# πŸ†ˆ or β“Ž = UTCβˆ’12
# πŸ†‰ or Ⓩ = UTC
# Take first argument as time (as 24hr clock, e.g. 23:00) or use the current system's local time
if echo "${1:-}" | grep -q :; then
CURRENT_TIME="$1"
shift 1
else
CURRENT_TIME="$(date '+%H:%M')"
fi
# Use additional arguments as $ON_STATE and $OFF_STATE emojis
ON_STATE="${1:-πŸ”΄}"
OFF_STATE="${2:-⚫️}"
# Fall back to $OFF_STATE if $YOUR_LOCATION is not defined
[ -z "${YOUR_LOCATION:-}" ] && YOUR_LOCATION="$OFF_STATE"
# Convert time to binary using emojis to display
to_binary_emojis() {
echo "obase=2;$1" | bc | sed 's/^/00000/' | tail -c$2 | sed "s/1/$ON_STATE/g;s/0/$OFF_STATE/g"
}
# Print result
cat <<EOF
$YOUR_LOCATION$(to_binary_emojis "${CURRENT_TIME%:*}" 6)
$(to_binary_emojis "${CURRENT_TIME#*:}" 7)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment