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
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
# Sync notes via git
|
# Sync notes via git
|
||||||
notesSync() {
|
notesSync() {
|
||||||
|
|
||||||
|
# check if online
|
||||||
|
test="git.sr.ht"
|
||||||
|
if timeout 0.5 ping -q -c 1 -W 1 $test >/dev/null; then
|
||||||
{
|
{
|
||||||
path="${notes_dir}/"
|
path="${notes_dir}/"
|
||||||
cd "$path"
|
cd "$path"
|
||||||
|
@ -13,4 +17,5 @@ notesSync() {
|
||||||
# Report; TODO: write log
|
# Report; TODO: write log
|
||||||
echo ">>> Sync failed"
|
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
|
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
|
||||||
|
|
2
notes.sh
2
notes.sh
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue