diff --git a/functions.sh b/functions.sh new file mode 100644 index 0000000..1a1a997 --- /dev/null +++ b/functions.sh @@ -0,0 +1,14 @@ +notesSync() { + { + path="${notes_dir}/" + cd "$path" + git pull --quiet + git add . + git commit -m "[script] update/add entrie/s" --quiet + git push --quiet + echo ">>> Sync success" + } || { + # Report; TODO: write log + echo ">>> Sync failed" + } +} diff --git a/journal.sh b/journal.sh index 0d86dcb..1b5bea1 100755 --- a/journal.sh +++ b/journal.sh @@ -1,7 +1,8 @@ #! /usr/bin/bash -# Load config +# Load config & functions . ${HOME}/ayo.conf +. functions.sh command=$1 journal_dir="${notes_dir}/Journal" @@ -13,22 +14,13 @@ file_name=$(date +'%m.%d.%Y').md full_path="${journal_dir}/${month_dir}/${file_name}" if [ "$1" = "sync" ]; then - { - path="${notes_dir}/" - cd "$path" - git pull - git add . - git commit -m "[script] update/add entrie/s" - git push - } || { - # Report; TODO: write log - echo ">>> Sync failed" - } + notesSync elif [ "$1" = "append" ]; then { read -p "Add thought: " thought time=$(date +'%r') echo $'\n'\[$time\] $thought$'\n' >> "$full_path" + notesSync } || { echo ">>> Append failed" } @@ -48,6 +40,7 @@ else else vim "$full_path" fi + notesSync } || { # Report; TODO: write log echo ">>> " $full_path diff --git a/notes.sh b/notes.sh index c39c426..9bdd0ad 100755 --- a/notes.sh +++ b/notes.sh @@ -4,6 +4,7 @@ # Load config . ${HOME}/ayo.conf +. functions.sh # TODO: write log for echoes with >>> @@ -12,16 +13,7 @@ command=$1 getopts "t" typora; #check if -t flag is given if [ "$1" = "sync" ]; then - { - path="${notes_dir}/" - cd "$path" - git pull - git add . - git commit -m "[script] update/add entrie/s" - git push - } || { - echo ">>> Sync failed" - } + notesSync else { read -p "Enter file name: " title @@ -44,6 +36,8 @@ else else vim "$full_path" fi + + notesSync } || { echo ">>> New note failed" }