feat(notes, journal): offline scenario (quiet check for network conection for notesSync

This commit is contained in:
Ayo Ayco 2025-06-23 17:47:13 +02:00
parent f90d60f30d
commit 864bc2840c
3 changed files with 32 additions and 22 deletions

View file

@ -2,15 +2,20 @@
# Sync notes via git # Sync notes via git
notesSync() { notesSync() {
{
path="${notes_dir}/" # check if online
cd "$path" test="git.sr.ht"
git pull --quiet if timeout 0.5 ping -q -c 1 -W 1 $test >/dev/null; then
git add . {
git commit -m "[bash script] update/add entries" >> /dev/null path="${notes_dir}/"
git push --quiet cd "$path"
} || { git pull --quiet
# Report; TODO: write log git add .
echo ">>> Sync failed" git commit -m "[bash script] update/add entries" >> /dev/null
} git push --quiet
} || {
# Report; TODO: write log
echo ">>> Sync failed"
}
fi
} }

View file

@ -13,15 +13,7 @@ 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" = "append" ]; then function createEntry() {
{
read -p "Add thought: " thought
time=$(date +'%r')
echo $'\n'\> \[$time\]$'\n'\> $thought >> "$full_path"
} || {
echo ">>> Append failed"
}
else
{ {
# IF Not Exists: create file & echo date # IF Not Exists: create file & echo date
if ! test -f "$full_path"; then if ! test -f "$full_path"; then
@ -41,6 +33,19 @@ else
# Report; TODO: write log # Report; TODO: write log
echo ">>> " $full_path echo ">>> " $full_path
} }
fi }
notesSync 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

View file

@ -12,6 +12,7 @@ command=$1
getopts "t" typora; #check if -t flag is given getopts "t" typora; #check if -t flag is given
notesSync
{ {
read -p "Enter file name: " title read -p "Enter file name: " title
file_name=$title.md file_name=$title.md
@ -37,5 +38,4 @@ getopts "t" typora; #check if -t flag is given
} || { } || {
echo ">>> New note failed" echo ">>> New note failed"
} }
notesSync notesSync