feat(notes, journal): offline scenario (quiet check for network conection for notesSync
This commit is contained in:
parent
f90d60f30d
commit
864bc2840c
3 changed files with 32 additions and 22 deletions
27
functions.sh
27
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
|
||||
}
|
||||
|
|
25
journal.sh
25
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
|
||||
|
|
2
notes.sh
2
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
|
||||
|
|
Loading…
Reference in a new issue