-
-
Save ruario/4ac6cc6086f830a836dfc6242574ca9b to your computer and use it in GitHub Desktop.
Prints the time in binary using emojis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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