1 # check if GITCLIENT has been set or set it to the output of hostname
2 if [ -z $GITCLIENT ]; then
3 GITCLIENT
=$
( hostname
)
5 # returns true if the argument provided directory is a git repository
10 if git rev-parse
2>/dev
/null
; then
18 # sync local repository to remote
20 if [[ $USEGIT && -n $GITREMOTE ]]; then
22 # LASTSYNC is the last time we synced to the remote, or 0 if it's the first time.
23 LASTSYNC
=$
($JQ -r '.git["lastpull"] // 0' "$DB")
24 [ $PLAIN == false
] && echo "Syncing notes with git on remote \"$GITREMOTE\""
25 SYNCDIFF
=$
(( ${NOWSYNC} - ${LASTSYNC} ))
26 if (( $SYNCDIFF > $GITSYNCDELAY )); then
27 #more than our delay time has passed. We can sync again.
28 $JQ --arg n
"$NOWSYNC" '.git["lastpull"] = $n' "$DB" > $TMPDB
33 # Last synced less than $GITSYNCDELAY seconds ago. We shall wait
34 [ $PLAIN == false
] && echo "Last synced less than $GITSYNCDELAY seconds ago. We shall wait"
37 # no git, so we just keep going
42 # add note to git and push it to remote
44 if [[ $USEGIT && -n $GITREMOTE ]]; then
45 [ $PLAIN == false
] && echo "Adding note to remote \"$GITREMOTE\""
48 $GIT commit
-m "$(basename $0) - adding note from ${GITCLIENT}"
49 $GIT push origin master
51 # no git, so we just keep going
56 # check for USEGIT and subsequent variables
57 if [[ $USEGIT && -n $GITREMOTE ]]; then
59 if ! is_git_repo
$BASEDIR; then
60 # initializing git repository
63 echo "adding all files to git"
65 $GIT commit
-m "$(basename $0) - initial commit from ${GITCLIENT}"
66 $GIT remote add origin
$GITREMOTE
67 $GIT push
-u origin master
69 elif [[ $USEGIT && -z $GITREMOTE ]]; then
70 echo "GITREMOTE variable not set. reverting USEGIT to false"