summaryrefslogtreecommitdiff
path: root/watch-calendars
blob: 4ba4250c5dc49629a0c2ab53734b2e5cf95505a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

lock_file=/tmp/watch-calendars.lock

if [ $# -eq 0 ]; then
  if [ -r "${lock_file}" ] \
  && kill -0 "$(cat "${lock_file}")"; then
    exit
  fi

  echo $$ >"${lock_file}"
  trap 'rm "${lock_file:?}"' EXIT

  find ~/.local/share/khal/calendars \
    -mindepth 1 \
    -maxdepth 1 \
    -type d \
  | parallel -j0 "$0"
  exit $?
fi

while [ -d "$1" ]; do
  inotifywait --exclude .git -r -e CREATE,MOVED_TO,DELETE -t 30 "$1"
  git -C "$1" add -A
  git -C "$1" commit -m'update by '"$(whoami)"'@'"$(uname -n)"' on '"$(date)"
  git -C "$1" pull --rebase
  git -C "$1" push
done