feat: shared functions.sh with notesSync function; quiet git operations"
This commit is contained in:
parent
1681745c09
commit
888ff8ef55
3 changed files with 23 additions and 22 deletions
14
functions.sh
Normal file
14
functions.sh
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
17
journal.sh
17
journal.sh
|
@ -1,7 +1,8 @@
|
||||||
#! /usr/bin/bash
|
#! /usr/bin/bash
|
||||||
|
|
||||||
# Load config
|
# Load config & functions
|
||||||
. ${HOME}/ayo.conf
|
. ${HOME}/ayo.conf
|
||||||
|
. functions.sh
|
||||||
|
|
||||||
command=$1
|
command=$1
|
||||||
journal_dir="${notes_dir}/Journal"
|
journal_dir="${notes_dir}/Journal"
|
||||||
|
@ -13,22 +14,13 @@ 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" = "sync" ]; then
|
if [ "$1" = "sync" ]; then
|
||||||
{
|
notesSync
|
||||||
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"
|
|
||||||
}
|
|
||||||
elif [ "$1" = "append" ]; then
|
elif [ "$1" = "append" ]; then
|
||||||
{
|
{
|
||||||
read -p "Add thought: " thought
|
read -p "Add thought: " thought
|
||||||
time=$(date +'%r')
|
time=$(date +'%r')
|
||||||
echo $'\n'\[$time\] $thought$'\n' >> "$full_path"
|
echo $'\n'\[$time\] $thought$'\n' >> "$full_path"
|
||||||
|
notesSync
|
||||||
} || {
|
} || {
|
||||||
echo ">>> Append failed"
|
echo ">>> Append failed"
|
||||||
}
|
}
|
||||||
|
@ -48,6 +40,7 @@ else
|
||||||
else
|
else
|
||||||
vim "$full_path"
|
vim "$full_path"
|
||||||
fi
|
fi
|
||||||
|
notesSync
|
||||||
} || {
|
} || {
|
||||||
# Report; TODO: write log
|
# Report; TODO: write log
|
||||||
echo ">>> " $full_path
|
echo ">>> " $full_path
|
||||||
|
|
14
notes.sh
14
notes.sh
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
# Load config
|
# Load config
|
||||||
. ${HOME}/ayo.conf
|
. ${HOME}/ayo.conf
|
||||||
|
. functions.sh
|
||||||
|
|
||||||
# TODO: write log for echoes with >>>
|
# TODO: write log for echoes with >>>
|
||||||
|
|
||||||
|
@ -12,16 +13,7 @@ command=$1
|
||||||
getopts "t" typora; #check if -t flag is given
|
getopts "t" typora; #check if -t flag is given
|
||||||
|
|
||||||
if [ "$1" = "sync" ]; then
|
if [ "$1" = "sync" ]; then
|
||||||
{
|
notesSync
|
||||||
path="${notes_dir}/"
|
|
||||||
cd "$path"
|
|
||||||
git pull
|
|
||||||
git add .
|
|
||||||
git commit -m "[script] update/add entrie/s"
|
|
||||||
git push
|
|
||||||
} || {
|
|
||||||
echo ">>> Sync failed"
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
read -p "Enter file name: " title
|
read -p "Enter file name: " title
|
||||||
|
@ -44,6 +36,8 @@ else
|
||||||
else
|
else
|
||||||
vim "$full_path"
|
vim "$full_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
notesSync
|
||||||
} || {
|
} || {
|
||||||
echo ">>> New note failed"
|
echo ">>> New note failed"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue