From 864bc2840cba660f411ae442673dd14d5d09f582 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 23 Jun 2025 17:47:13 +0200 Subject: [PATCH] feat(notes, journal): offline scenario (quiet check for network conection for notesSync --- functions.sh | 27 ++++++++++++++++----------- journal.sh | 25 +++++++++++++++---------- notes.sh | 2 +- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/functions.sh b/functions.sh index ad858aa..99ee889 100644 --- a/functions.sh +++ b/functions.sh @@ -2,15 +2,20 @@ # Sync notes via git notesSync() { - { - path="${notes_dir}/" - cd "$path" - git pull --quiet - git add . - git commit -m "[bash script] update/add entries" >> /dev/null - git push --quiet - } || { - # Report; TODO: write log - echo ">>> Sync failed" - } + + # check if online + test="git.sr.ht" + if timeout 0.5 ping -q -c 1 -W 1 $test >/dev/null; then + { + path="${notes_dir}/" + cd "$path" + git pull --quiet + git add . + git commit -m "[bash script] update/add entries" >> /dev/null + git push --quiet + } || { + # Report; TODO: write log + echo ">>> Sync failed" + } + fi } diff --git a/journal.sh b/journal.sh index 8b79ddc..1c916ae 100755 --- a/journal.sh +++ b/journal.sh @@ -13,15 +13,7 @@ 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" = "append" ]; then - { - read -p "Add thought: " thought - time=$(date +'%r') - echo $'\n'\> \[$time\]$'\n'\> $thought >> "$full_path" - } || { - echo ">>> Append failed" - } -else +function createEntry() { { # IF Not Exists: create file & echo date if ! test -f "$full_path"; then @@ -41,6 +33,19 @@ else # Report; TODO: write log echo ">>> " $full_path } -fi +} notesSync +if [ "$1" = "append" ]; then + { + read -p "Add thought: " thought + time=$(date +'%r') + echo $'\n'\> \[$time\]$'\n'\> $thought >> "$full_path" + + } || { + echo ">>> Append failed" + } +else + createEntry +fi +notesSync diff --git a/notes.sh b/notes.sh index 91779e5..0558670 100755 --- a/notes.sh +++ b/notes.sh @@ -12,6 +12,7 @@ command=$1 getopts "t" typora; #check if -t flag is given +notesSync { read -p "Enter file name: " title file_name=$title.md @@ -37,5 +38,4 @@ getopts "t" typora; #check if -t flag is given } || { echo ">>> New note failed" } - notesSync