From e68accc60ecbeb5e80c34c58ddcbfeff858b82ba Mon Sep 17 00:00:00 2001 From: Tony Blyler Date: Thu, 4 Apr 2019 10:34:45 -0400 Subject: [PATCH] Add note taking --- home/.scripts/note.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 home/.scripts/note.sh diff --git a/home/.scripts/note.sh b/home/.scripts/note.sh new file mode 100644 index 0000000..ea8833f --- /dev/null +++ b/home/.scripts/note.sh @@ -0,0 +1,26 @@ +note() { + local DATE="$(date '+%s')" + local BASE_NOTE_PATH="${NOTE_PATH:-$(pwd)}" + local IS_DATE_PATH=1 + if [[ "${1}" =~ '^ *[-+]{0,1}[0-9]+ *$' ]]; then + local DAY=86400 + local DATE=$(( DATE + (DAY * ${1}) )) + + elif [[ -n "${1}" ]]; then + local IS_DATE_PATH='' + local NOTE_PATH="${BASE_NOTE_PATH}/${1}" + if ! [[ "${1}" =~ '\.[mM][dD]$' ]]; then + local NOTE_PATH="${NOTE_PATH}.md" + fi + fi + + if [[ ${IS_DATE_PATH} ]]; then + local NOTE_PATH="${BASE_NOTE_PATH}/$(date --date "@${DATE}" '+%Y/%m')" + mkdir -p "${NOTE_PATH}" || return 1 + local NOTE_PATH="${NOTE_PATH}/$(date --date "@${DATE}" '+%d').md" + else + mkdir -p "$(dirname "${NOTE_PATH}")" || return 2 + fi + + vim "${NOTE_PATH}" || return 3 +}