scripts/functions.sh

48 lines
1,001 B
Bash

# NOTE: config should be loaded by the script using this shared functions.sh
bold=$(tput bold)
dlob=$(tput sgr0)
retries=0
# Sync notes via git
notesSync() {
# check if online
test="git.sr.ht"
time="0.5"
max_retries=5
if timeout $time ping -q -c 1 -W 1 $test >/dev/null; then
{
path="${notes_dir}/"
cd "$path"
git pull --quiet --rebase --autostash
git add .
git commit -m "[bash script] update/add entries" >> /dev/null
git push --quiet
echo ">>> Sync success"
} || {
# Report; TODO: write log
echo ">>> Sync failed"
}
else
echo ">>> Sync skipped due to timeout ($time)"
retries=$(($retries + 1))
echo "retrying ($retries/$max_retries)..."
if [ $retries -eq $max_retries ]; then
return
else
notesSync
fi
fi
}
yes_or_no() {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
esac
done
}