moon 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/sh
  2. # http://smithje.github.io/bash/2013/07/08/moon-phase-prompt.html
  3. # ◯ ☽ ◗ ◑ ● ◐ ◖ ☾
  4. get_phase_day () {
  5. local lunar_phase=2551443
  6. local now=$(date -u +"%s")
  7. local newmoon=592500
  8. local phase=$((($now - $newmoon) % $lunar_phase))
  9. echo $(((phase / 86400) + 1))
  10. }
  11. get_moon_icon () {
  12. local phase_number=$(get_phase_day)
  13. # Multiply by 100000 so we can do integer comparison. Go Bash!
  14. local phase_number_biggened=$((phase_number * 100000))
  15. if [ $phase_number_biggened -lt 184566 ]; then phase_icon="new"
  16. elif [ $phase_number_biggened -lt 553699 ]; then phase_icon="waxing crescent"
  17. elif [ $phase_number_biggened -lt 922831 ]; then phase_icon="first quarter"
  18. elif [ $phase_number_biggened -lt 1291963 ]; then phase_icon="waxing gibbous"
  19. elif [ $phase_number_biggened -lt 1661096 ]; then phase_icon="full"
  20. elif [ $phase_number_biggened -lt 2030228 ]; then phase_icon="waning gibbous"
  21. elif [ $phase_number_biggened -lt 2399361 ]; then phase_icon="last quarter"
  22. elif [ $phase_number_biggened -lt 2768493 ]; then phase_icon="waning crescent"
  23. else phase_icon="new"
  24. # if [ $phase_number_biggened -lt 184566 ]; then phase_icon="◯" # new
  25. # elif [ $phase_number_biggened -lt 553699 ]; then phase_icon="☽" # waxing crescent
  26. # elif [ $phase_number_biggened -lt 922831 ]; then phase_icon="◗" # first quarter
  27. # elif [ $phase_number_biggened -lt 1291963 ]; then phase_icon="◑" # waxing gibbous
  28. # elif [ $phase_number_biggened -lt 1661096 ]; then phase_icon="●" # full
  29. # elif [ $phase_number_biggened -lt 2030228 ]; then phase_icon="◐" # waning gibbous
  30. # elif [ $phase_number_biggened -lt 2399361 ]; then phase_icon="◖" # last quarter
  31. # elif [ $phase_number_biggened -lt 2768493 ]; then phase_icon="☾" # waning crescent
  32. # else phase_icon="◯" # new
  33. fi
  34. echo $phase_icon
  35. }
  36. get_moon_icon