Created
September 24, 2016 15:14
-
-
Save ablwr/127b3053d0f1a0316230b65f8bef6ccb to your computer and use it in GitHub Desktop.
get the moon in your bash profile
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
function moonphase() { | |
/usr/bin/env ruby <<-EORUBY | |
# Convert a date to Julian. | |
def julian(year, month, day) | |
a = (14-month)/12 | |
y = year+4800-a | |
m = (12*a)-3+month | |
return day + (153*m+2)/5 + (365*y) + y/4 - y/100 + y/400 - 32045 | |
end | |
# Define the phases of the moon. | |
def phase(year, month, day) | |
p = (julian(year, month, day) - julian(2000, 1, 6)) % 29.530588853 | |
if p < 1.84566 then return "π" # new | |
elsif p < 5.53699 then return "π" # waxing crescent | |
elsif p < 9.22831 then return "π" # first quarter | |
elsif p < 12.91963 then return "π" # waxing gibbous | |
elsif p < 16.61096 then return "π" # full | |
elsif p < 20.30228 then return "π" # waning gibbous | |
elsif p < 23.99361 then return "π" # last quarter | |
elsif p < 27.68493 then return "π" # waning crescent | |
else return "π" # new | |
end | |
end | |
# Get today's phase. | |
today = Time.new | |
print "#{phase(today.year, today.month, today.day)}" | |
EORUBY | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment