####################################### # Normalizes date arguments # Globals: # None # Arguments: # date (defaults to today) # Returns: # string of format 'YYYY-MM-DD' ####################################### function getDate { local DATE=${1:-$(date -I)}; if [[ "${DATE}" =~ [+]+ ]]; then DATE=$(date -I -d" ${DATE} days"); elif [[ "${DATE}" =~ ^- ]]; then DATE=$(date -I -d" ${DATE} days"); elif [[ "${DATE}" == "tomorrow" ]]; then DATE=$(date -I -d" +1 days"); elif [[ "${DATE}" == "yesterday" ]]; then DATE=$(date -I -d" -1 days"); fi echo "${DATE}"; } ####################################### # Load a journal file # Globals: # None # Arguments: # date (defaults to today) # Returns: # None ####################################### function journal { local DATE=$(getDate "$1"); emacs ~/notes/journal/${DATE}.md; }
case "$DATE" in +*|-*) DATE=$(date -I -d" $DATE days") ;; tomorrow) DATE=$(date -I -d" +1 days") ;; yesterday) DATE=$(date -I -d" -1 days") ;; esac