#!/bin/sh
#
# diary - opens file at $DIARY/year-month-day.md with $EDITOR (default: vim)

# diary() {
#   root="${HOME}/.local/share/journal"
#   date="$(date -u +"%Y/%m/%d")"
#   dir="${root}/${date}"
#   name="$(date -u +"%T")"
#   if [ ! -z "$1" ]; then
#     name+=" '$1'"
#   fi
#   path="${dir}/${name}"
#   mkdir -p "${dir}"
#   ${EDITOR:-vi} "${path}"
# }

diary="${DIARY:-${HOME}/diary}"

if [ ! -d "${diary}" ]; then
  echo "${diary} does not exist"
  exit
fi

date=$(date +%Y-%m-%d)
file=${diary}/${date}.md
time=$(date +%c)

echo "${time}" >>"${file}"
exec ${EDITOR:-vi} "${file}"
