feat: auto sync for notes & journal

This commit is contained in:
Ayo Ayco 2025-06-23 14:34:00 +02:00
parent 8909dbe41e
commit 5fcf06c7aa
2 changed files with 31 additions and 32 deletions

View file

@ -13,14 +13,13 @@ getopts "t" typora; #check if -t flag is given
file_name=$(date +'%m.%d.%Y').md file_name=$(date +'%m.%d.%Y').md
full_path="${journal_dir}/${month_dir}/${file_name}" full_path="${journal_dir}/${month_dir}/${file_name}"
if [ "$1" = "sync" ]; then notesSync
notesSync
elif [ "$1" = "append" ]; then if [ "$1" = "append" ]; then
{ {
read -p "Add thought: " thought read -p "Add thought: " thought
time=$(date +'%r') time=$(date +'%r')
echo $'\n'\> \[$time\]$'\n'\> $thought >> "$full_path" echo $'\n'\> \[$time\]$'\n'\> $thought >> "$full_path"
notesSync
} || { } || {
echo ">>> Append failed" echo ">>> Append failed"
} }
@ -40,9 +39,10 @@ else
else else
vim "$full_path" vim "$full_path"
fi fi
notesSync
} || { } || {
# Report; TODO: write log # Report; TODO: write log
echo ">>> " $full_path echo ">>> " $full_path
} }
fi fi
notesSync

View file

@ -12,33 +12,32 @@ command=$1
getopts "t" typora; #check if -t flag is given getopts "t" typora; #check if -t flag is given
if [ "$1" = "sync" ]; then notesSync
notesSync
else
{
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 read -p "Enter file name: " title
install -Dv /dev/null "$full_path" file_name=$title.md
# TODO: update to correct heading from old entries full_path="${notes_dir}/${file_name}"
heading="# $title"
echo $heading > "$full_path"
date_heading=$(date +'%b %d, %Y, %a %r')
echo $date_heading >> "$full_path"
fi
# Open in editor # IF Not Exists: create file & echo date
if [ "$typora" = "t" ]; then if ! test -f "$full_path"; then
typora "$full_path" install -Dv /dev/null "$full_path"
else # TODO: update to correct heading from old entries
vim "$full_path" heading="# $title"
fi echo $heading > "$full_path"
date_heading=$(date +'%b %d, %Y, %a %r')
echo $date_heading >> "$full_path"
fi
notesSync # Open in editor
} || { if [ "$typora" = "t" ]; then
echo ">>> New note failed" typora "$full_path"
} else
fi vim "$full_path"
fi
} || {
echo ">>> New note failed"
}
notesSync