Skip to content

Instantly share code, notes, and snippets.

@Raimondi
Created August 23, 2017 01:37
Show Gist options
  • Save Raimondi/9b9c19f1003a361fb19bdcd38bd23987 to your computer and use it in GitHub Desktop.
Save Raimondi/9b9c19f1003a361fb19bdcd38bd23987 to your computer and use it in GitHub Desktop.
#!/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