1 # returns true if the argument provided directory is a git repository
6 if git rev-parse
2>/dev
/null
; then
14 # sync local repository to remote
17 # LASTSYNC is the last time we synced to the remote, or 0 if it's the first time.
18 LASTSYNC
=$
($JQ -r '.git["lastpull"] // 0' "$DB")
19 [ $PLAIN == false
] && echo "Syncing notes with git on remote \"$GITREMOTE\""
20 SYNCDIFF
=$
(( ${NOWSYNC} - ${LASTSYNC} ))
21 if (( $SYNCDIFF > $GITSYNCDELAY )); then
22 #more than our delay time has passed. We can sync again.
23 $JQ --arg n
"$NOWSYNC" '.git["lastpull"] = $n' "$DB" > $TMPDB
28 # Last synced less than $GITSYNCDELAY seconds ago. We shall wait
29 [ $PLAIN == false
] && echo "Last synced less than $GITSYNCDELAY seconds ago. We shall wait"
33 # check for USEGIT and subsequent variables
34 if [[ $USEGIT && -n $GITREMOTE ]]; then
36 if ! is_git_repo
$BASEDIR; then
37 # initializing git repository
40 echo "adding all files to git"
42 $GIT commit
-m "$(basename $0) - initial commit"
43 $GIT remote add origin
$GITREMOTE
44 $GIT push
-u origin master
46 elif [[ $USEGIT && -z $GITREMOTE ]]; then
47 echo "GITREMOTE variable not set. reverting USEGIT to false"