From 5fcf06c7aa12284d3f3d874d5b1c563eb1154305 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 23 Jun 2025 14:34:00 +0200 Subject: [PATCH] feat: auto sync for notes & journal --- journal.sh | 10 +++++----- notes.sh | 53 ++++++++++++++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/journal.sh b/journal.sh index 9448d9f..8bf1c77 100755 --- a/journal.sh +++ b/journal.sh @@ -13,14 +13,13 @@ getopts "t" typora; #check if -t flag is given file_name=$(date +'%m.%d.%Y').md full_path="${journal_dir}/${month_dir}/${file_name}" -if [ "$1" = "sync" ]; then - notesSync -elif [ "$1" = "append" ]; then +notesSync + +if [ "$1" = "append" ]; then { read -p "Add thought: " thought time=$(date +'%r') echo $'\n'\> \[$time\]$'\n'\> $thought >> "$full_path" - notesSync } || { echo ">>> Append failed" } @@ -40,9 +39,10 @@ else else vim "$full_path" fi - notesSync } || { # Report; TODO: write log echo ">>> " $full_path } fi + +notesSync diff --git a/notes.sh b/notes.sh index 6298845..15e4951 100755 --- a/notes.sh +++ b/notes.sh @@ -12,33 +12,32 @@ command=$1 getopts "t" typora; #check if -t flag is given -if [ "$1" = "sync" ]; then - notesSync -else - { - read -p "Enter file name: " title - file_name=$title.md - full_path="${notes_dir}/${file_name}" +notesSync - # 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 +{ + read -p "Enter file name: " title + file_name=$title.md + full_path="${notes_dir}/${file_name}" - # Open in editor - if [ "$typora" = "t" ]; then - typora "$full_path" - else - vim "$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 + heading="# $title" + echo $heading > "$full_path" + date_heading=$(date +'%b %d, %Y, %a %r') + echo $date_heading >> "$full_path" + fi - notesSync - } || { - echo ">>> New note failed" - } -fi + # Open in editor + if [ "$typora" = "t" ]; then + typora "$full_path" + else + vim "$full_path" + fi + +} || { + echo ">>> New note failed" +} + +notesSync