Skip to content

Instantly share code, notes, and snippets.

@Crysknife007
Forked from zuloo/moonphase.sh
Last active March 23, 2024 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Crysknife007/29b00826c86b9a91945ce6e4efccc2b5 to your computer and use it in GitHub Desktop.
Save Crysknife007/29b00826c86b9a91945ce6e4efccc2b5 to your computer and use it in GitHub Desktop.
moonphase bash script
#!/bin/bash
# Calculate approximate moon phase
moonphase(){
local lp=2551443
local now=$(date -u +"%s")
local newmoon=592500
local phase=$((($now - $newmoon) % $lp))
local phase_number=$((((phase / 86400) + 1)*100000))
# Multiply by 100000 so that we can do integer comparison in bash.
if [ $phase_number -lt 184566 ]; then phase_icon="○ New"
elif [ $phase_number -lt 553699 ]; then phase_icon="❩ Waxing Crescent"
elif [ $phase_number -lt 922831 ]; then phase_icon="◗ First Quarter"
elif [ $phase_number -lt 1291963 ]; then phase_icon="◑ Waxing Gibbous"
elif [ $phase_number -lt 1661096 ]; then phase_icon="● Full"
elif [ $phase_number -lt 2030228 ]; then phase_icon="◐ Waning Gibbous"
elif [ $phase_number -lt 2399361 ]; then phase_icon="◖ Last Quarter"
elif [ $phase_number -lt 2768493 ]; then phase_icon="❨ Waning Crescent"
else
phase_icon="○ New"
fi
# Get the current phase day
number=$(($phase_number/100000));
# Echo the current Moon Phase Icon, name, and day number
echo $phase_icon Moon. Day $number
}
# Run the function
moonphase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment