Created
August 23, 2017 01:37
-
-
Save Raimondi/9b9c19f1003a361fb19bdcd38bd23987 to your computer and use it in GitHub Desktop.
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 | |
# https://smithje.github.io/bash/2013/07/08/moon-phase-prompt | |
get_phase_day () { | |
local lp=2551443 | |
local now=$(date -ju +"%s") | |
local newmoon=592500 | |
local phase=$((($now - $newmoon) % $lp)) | |
echo $(((phase / 86400) + 1)) | |
} | |
get_moon_icon () { | |
local phase_number=$(get_phase_day) | |
# Multiply by 100000 so we can do integer comparison. Go Bash! | |
local phase_number_biggened=$((phase_number * 100000)) | |
if [ $phase_number_biggened -lt 184566 ]; then phase_icon="π" # new | |
elif [ $phase_number_biggened -lt 553699 ]; then phase_icon="π" # waxing crescent | |
elif [ $phase_number_biggened -lt 922831 ]; then phase_icon="π" # first quarter | |
elif [ $phase_number_biggened -lt 1291963 ]; then phase_icon="π" # waxing gibbous | |
elif [ $phase_number_biggened -lt 1661096 ]; then phase_icon="π" # full | |
elif [ $phase_number_biggened -lt 2030228 ]; then phase_icon="π" # waning gibbous | |
elif [ $phase_number_biggened -lt 2399361 ]; then phase_icon="π" # last quarter | |
elif [ $phase_number_biggened -lt 2768493 ]; then phase_icon="π" # waning crescent | |
else phase_icon="π" # new | |
fi | |
echo $phase_icon | |
} | |
get_moon_icon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment