From 098f12f49784b2811f721ae9ed7d939d5b2e20f6 Mon Sep 17 00:00:00 2001 From: Ayo Date: Sun, 22 Jun 2025 16:01:37 +0200 Subject: [PATCH] feat(journal): new note command --- ayo.sh | 10 +++++++++- journal.sh | 53 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/ayo.sh b/ayo.sh index b0c4266..a5301bd 100755 --- a/ayo.sh +++ b/ayo.sh @@ -1,9 +1,17 @@ #! /usr/bin/bash case $1 in - js) + ## SHORTCUTS + + js) # js - journal sync . ${HOME}/Projects/scripts/journal.sh sync ;; + jn) # js - journal note + . ${HOME}/Projects/scripts/journal.sh note + ;; + + ## SCRIPTS + j | journal) . ${HOME}/Projects/scripts/journal.sh $2 $3 $4 $5 ;; diff --git a/journal.sh b/journal.sh index 0e2f7b2..8ae0338 100755 --- a/journal.sh +++ b/journal.sh @@ -20,22 +20,45 @@ if [ "$1" = "sync" ]; then # Report; TODO: write log echo ">>> Sync failed" } +elif [ "$1" = "note" ]; then + { + read -p "Enter file name: " title + file_name=$title.md + full_path="${notes_dir}/${file_name}" + + # IF Not Exists: create file & echo date + if ! test -f "$full_path"; then + install -Dv /dev/null "$full_path" + # TODO: update to correct heading from old entries + heading="# $title" + echo $heading > "$full_path" + date_heading=$(date +'%b %d, %Y, %a %r') + echo $date_heading >> "$full_path" + fi + + # Open in editor + vim "$full_path" + + } || { + echo ">>> New note failed" + } else - file_name=$(date +'%m.%d.%Y').md - full_path="${journal_dir}/${month_dir}/${file_name}" + { + file_name=$(date +'%m.%d.%Y').md + full_path="${journal_dir}/${month_dir}/${file_name}" - # IF Not Exists: create file & echo date - if ! test -f "$full_path"; then - install -Dv /dev/null "$full_path" - # TODO: update to correct heading from old entries - # Jun 17, 2025, Tue 10:24 PM - heading=$(date +'%b %d, %Y, %a %r') - echo $heading > "$full_path" - fi + # IF Not Exists: create file & echo date + if ! test -f "$full_path"; then + install -Dv /dev/null "$full_path" + # TODO: update to correct heading from old entries + date_heading=$(date +'%b %d, %Y, %a %r') + echo $date_heading > "$full_path" + fi - # Open in editor - typora "$full_path" - - # Report; TODO: write log - echo ">>> " $full_path + # Open in editor + vim "$full_path" + } || { + # Report; TODO: write log + echo ">>> " $full_path + } fi