#!/bin/bash
#                       /usr/local/bin/now
# https://crystalfaeries.net/posix/bin/now
# celeste:crystalfaery NOW 2021-02-21 08:29:15+00:00
(( fold=64 ))	# how wide can our lines be?
case $# in
0)	# 2019-06-29 17:35:33+00:00 e.g. UTC
	date -u --rfc-3339=seconds
	exit $?
	;;
*)	#
	case "${1}" in
	-v | --version)	# VERSION
		head -n 4 "${0}" | tail -n 1	1>&2
		exit	$?
		;;
	-h | --help)	# HELP!?!
		echo "$0: -v or --version option displays the script's  version information"		1>&2
		echo "$0: -h or --help    option spews this (hopefully) helpful information"		1>&2
		echo "$0: -n DATE:      generates 2 or 3 lines of Numerology+Tarot for DATE"		1>&2
		echo "$0: -n:           generates 2 or 3 lines of Numerology+Tarot  du jour"		1>&2
		echo "$0: -d:			20190821 i.e. date    for utilization in a filename"	1>&2
		echo "$0: -t:			201908211946 e.g. date+time   for use in a filename"	1>&2
		echo "$0: -f:			2019-08-21.19-50 e.g. for utilization in a filename"	1>&2
		echo "$0: without options:	2019-08-21 19:46:57+00:00 i.e. UTC"			1>&2
		exit	$?
		;;
	-t)	# date+time without punctuation
		date -u --rfc-3339=seconds | sed 's/:[0-9][0-9]+00:00// ; s/ //g ; s/:// ; s/-//g'
		exit	$?
		;;
	-d)	# date      without punctuation
		date -u --rfc-3339=seconds | sed 's/:[0-9][0-9]+00:00// ; s/ //g ; s/:// ; s/-//g ; s/[0-9][0-9][0-9][0-9]$//'
		exit	$?
		;;
	-f)	# 2019-06-29.17-35 e.g. for inclusion in a filename.
		date -u --rfc-3339=seconds | sed 's/:[0-9][0-9]+00:00// ; s/ /./g ; s/:/-/'
		exit	$?
		;;
	-n)	# numerology of the day
		shift
		if [ "${1}" == "" ]
		then  # TOday is requested
			thedate="$(date +%Y-%m-%d)"
			today="$(date '+%A')"
		else  # A DATE was specified as an argument to -n
			thedate="$(date +%Y-%m-%d -d ${1})"
			(( result=$? ))
			if [[ $result -ne 0 ]]
			then
				echo "$0 -n ${1}: Date Error: $result" 1>&2
				exit $result
			fi
			today="$(date '+%A' -d "${1}")"
			(( result=$? ))
			if [[ $result -ne 0 ]]
			then
				echo "$0 -n ${1}: Date Error: $result" 1>&2
				exit $result
			fi
		fi
		case ${today} in
		Monday)	day="MoonDay";		tone="Unconscious fear, hope, desires";;
	       Tuesday)	day="MarsDay";		tone="Inner will, motivation";;
	     Wednesday)	day="MercuryDay";	tone="Rational Mind";;
	      Thursday)	day="JupiterDay";	tone="Consciousness Expansion";;
		Friday)	day="VenusDay";		tone="Conscious Relationships";;
	      Saturday)	day="SaturnDay";	tone="Overcoming Obstacles to Growth";;
		Sunday)	day="SunDay";		tone="Higher-Self Essence";;
		     *)	day="${today}";		tone="8 Days a Week";;
		esac
		echo -e "${thedate} ${day}'s numerology:"
		if [ "${1}" == "" ]
		then  # today is requested
			digits="$(date -u --rfc-3339=seconds | sed 's/:[0-9][0-9]+00:00// ; s/ //g ; s/:// ; s/-//g ; s/[0-9][0-9][0-9][0-9]$//')"
		else  # a date was specified as an argument to -n
			digits="$(date -u --rfc-3339=seconds -d "${1}" | sed 's/:[0-9][0-9]+00:00// ; s/ //g ; s/:// ; s/-//g ; s/[0-9][0-9][0-9][0-9]$//')"
		fi
		while [ "$digits" != "" ]
	    do
		(( sum=0 ))
		while [ "$digits" != "" ]
		do case "$digits" in
			0*) (( sum=sum+0 )) ;;
			1*) (( sum=sum+1 )) ;;
			2*) (( sum=sum+2 )) ;;
			3*) (( sum=sum+3 )) ;;
			4*) (( sum=sum+4 )) ;;
			5*) (( sum=sum+5 )) ;;
			6*) (( sum=sum+6 )) ;;
			7*) (( sum=sum+7 )) ;;
			8*) (( sum=sum+8 )) ;;
			9*) (( sum=sum+9 )) ;;
			*) echo "$digits";exit 1;;
		    esac
		    tmp=$(echo "$digits" | sed 's/^.//')
		    digits="${tmp}"
		done
		case "$sum" in
		0 ) echo -e "0 Fool";											digits=""
		    echo -e "${tone}:\nEccentric, spontaneous, original"						| fold -w $fold -s;;
		1 ) echo -e "1 Magician";										digits=""
		    echo -e "${tone}:\nWill, initiative, knowledge of universal 'secrets'"				| fold -w $fold -s;;
		2 ) echo -e "2 High Priestess";										digits=""
		    echo -e "${tone}:\nSecrecy, the unconscious, rhythms and cyclical changes"				| fold -w $fold -s;;
		3 ) echo -e "3 Empress";										digits=""
		    echo -e "${tone}:\nHarmony, love, fertility, Yin, <em>other</em>-consciousness"			| fold -w $fold -s;;
		4 ) echo -e "4 Emperor";										digits=""
		    echo -e "${tone}:\nStability, energy, ambition, Yang, <em>self</em>-consciousness"			| fold -w $fold -s;;
		5 ) echo -e "5 Heirophant";										digits=""
		    echo -e "${tone}:\nInspiration, intuition, patience, initiative, action"				| fold -w $fold -s;;
		6 ) echo -e "6 Lovers";											digits=""
		    echo -e "${tone}:\nLove and attraction, having to make choices, union of duality"			| fold -w $fold -s;;
		7 ) echo -e "7 Chariot";										digits=""
		    echo -e "${tone}:\n<em>Self</em>-sacrifice, adventure, will, hope"					| fold -w $fold -s;;
		8 ) echo -e "8 Justice = Kumari";									digits=""
		    echo -e "${tone}:\nEquilibrium, adjustment, suspended strength and action"				| fold -w $fold -s;;
		9 ) echo -e "9 Hermit";											digits=""
		    echo -e "${tone}:\nDiscipline, inner higher knowledge, the eternal seeker"				| fold -w $fold -s;;
		10) echo -e "10 Wheel of Fortune = 1 Magician";								digits=""
		    echo -e "${tone}:\nChange, karma, destiny, luck"							| fold -w $fold -s;;
		11) echo -e "11 Strength = 2 High Priestess";								digits=""
		    echo -e "${tone}:\nSpiritual Action, lust, strength, courage"					| fold -w $fold -s;;
		12) echo -e "12 Hanged Man = Ego Death = 3 Empress";							digits=""
		    echo -e "${tone}:\nReversal, sacrifice, surrender to higher forces"					| fold -w $fold -s;;
		13) echo -e "13 Death = 4 Emperor";									digits=""
		    echo -e "${tone}:\nSudden change, transformation, initiation, rebirth, the consequences of time"	| fold -w $fold -s;;
		14) echo -e "14 Temperance = Yang Puja = 5 Heirophant";							digits=""
		    echo -e "${tone}:\nSelf-control, reconciliation, combination of opposed forces"			| fold -w $fold -s;;
		15) echo -e "15 Devil = 6 Lovers";									digits=""
		    echo -e "${tone}:\nEndurance, materialism, secret plans, restrictions in one's possibilities"	| fold -w $fold -s;;
		16) echo -e "16 Tower = 7 Chariot";									digits=""
		    echo -e "${tone}:\nChange brought about by shock, awakening, liberation from an imprisoning reality"	| fold -w $fold -s;;
		17) echo -e "17 Star = Wish-Fulfilling Gem = 8 Kumari/Justice";						digits=""
		    echo -e "${tone}:\nHope, faith, trust, spiritual insight"						| fold -w $fold -s;;
		18) echo -e "18 Moon = 9 Hanged Man";									digits=""
		    echo -e "${tone}:\nCyclical or Voluntary change, ups and downs, illusions, deceptions"		| fold -w $fold -s;;
		19) echo -e "19 Sun = 10 Wheel of Fortune = 1 Mage";							digits=""
		    echo -e "${tone}:\nEnergy, liberation, frankness, joy, convalescence"				| fold -w $fold -s;;
		20) echo -e "20 Aeon = 2 High Priestess";								digits=""
		    echo -e "${tone}:\nRealization, end of the past and beginning of the future"				| fold -w $fold -s;;
		21) echo -e "21 Universe = 3 Empress";									digits=""
		    echo -e "${tone}:\nSynthesis, crystalization, unity success"						| fold -w $fold -s;;
		22) echo -e "22/0 Fool = 4 Emperor";									digits=""
		    echo -e "${tone}:\nMother's Milk = Spiritual Nourishment"						| fold -w $fold -s;;
		33) echo -e "33 Eternal Life = 6 Lovers";								digits=""
		    echo -e "${tone}:\nSpiritual Transcendence"								| fold -w $fold -s;;
		44) echo -e "44 Humming Bird = 8 Kumari/Justice";							digits=""
		    echo -e "${tone}:\nHeart's Joy"									| fold -w $fold -s;;
		*)  echo -e "$sum\n\t";											digits="$sum";;
		esac
	    done
	    ;;
	*)	echo "$0 does not cognize $1"	1>&2
		exit	-1
		;;
	esac
	;;
esac
exit	$?

