Created
June 12, 2018 06:44
-
-
Save benpitman/51f3a3cbcfd2ca09da4f66ae99febd13 to your computer and use it in GitHub Desktop.
A binary clock I made in Bash v4+ that runs in the background, updates every minute, and prints to the top right of the terminal.
This file contains hidden or 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/bash | |
tick() { | |
local \ | |
ampm \ | |
calibrate=true \ | |
D2B=({0..1}{0..1}{0..1}{0..1}{0..1}{0..1}) \ | |
hour \ | |
in_cli \ | |
minute \ | |
timestring | |
if ( [ -z "$DISPLAY" ] || [[ "$TERM" == "linux" ]] ); then | |
in_cli=true | |
else | |
in_cli=false | |
fi | |
while IFS='-' read hour minute ampm < <( date '+%I-%M-%p' ); do | |
timestring="${D2B[${hour#0*}]:2}:${D2B[${minute#0*}]} ${ampm,,}" | |
if ! $in_cli; then | |
timestring=${timestring//1/\\u25AE} | |
timestring=${timestring//0/\\u25AF} | |
fi | |
tput sc 2>/dev/null || printf '\e[s' | |
printf "\e[1;$(( $( tput cols ) - 13 ))H$timestring" | |
tput rc 2>/dev/null || printf '\e[u' | |
if $calibrate; then | |
until [[ $( date '+%S' ) == '00' ]]; do | |
sleep 0.5 | |
done | |
calibrate=false | |
continue | |
fi | |
sleep 60 | |
done | |
} | |
tick & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment