diff options
author | Sam Chudnick <sam@chudnick.com> | 2023-06-11 08:00:24 -0400 |
---|---|---|
committer | Sam Chudnick <sam@chudnick.com> | 2023-06-11 08:00:24 -0400 |
commit | 12ce8bdd65d3b5fcd6e8227eaecd5f772a90f8da (patch) | |
tree | 5be7566c5ef41877e1d03a013667fdae1aedf252 /.config/calcurse/hooks | |
parent | 9e82c96713989a7565eadac505b36e3dbe91cd5a (diff) |
Configuration file updates and additions.
Diffstat (limited to '.config/calcurse/hooks')
-rwxr-xr-x | .config/calcurse/hooks/post-save | 47 | ||||
-rwxr-xr-x | .config/calcurse/hooks/pre-load | 17 |
2 files changed, 64 insertions, 0 deletions
diff --git a/.config/calcurse/hooks/post-save b/.config/calcurse/hooks/post-save new file mode 100755 index 0000000..8836316 --- /dev/null +++ b/.config/calcurse/hooks/post-save | |||
@@ -0,0 +1,47 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # This is an example hook. It does two things whenever you save the data files: | ||
4 | # | ||
5 | # 1. Make a commit if the calcurse directories contain a Git repository. | ||
6 | # 2. Synchronize with a CalDAV server if calcurse-caldav is configured. | ||
7 | # | ||
8 | # In order to install this hook, copy this file to | ||
9 | # $XDG_CONFIG_HOME/calcurse/hooks/ (~/.config/calcurse/hooks/) or | ||
10 | # ~/.calcurse/hooks/ if using ~/.calcurse. | ||
11 | |||
12 | data_dir="$HOME/.calcurse" | ||
13 | config_dir="$HOME/.calcurse" | ||
14 | |||
15 | if [ ! -d "$data_dir" ]; then | ||
16 | data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse" | ||
17 | config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/calcurse" | ||
18 | fi | ||
19 | |||
20 | # Do not do anything when synchronizing with a CalDAV server. | ||
21 | [ -f "$data_dir/caldav/lock" ] && exit | ||
22 | |||
23 | # If the directory is under version control, create a Git commit. | ||
24 | commit_dir() { | ||
25 | cd "$1" >/dev/null 2>&1 || return | ||
26 | shift | ||
27 | if [ -d .git ] && command -v git >/dev/null; then | ||
28 | git add "$@" | ||
29 | if ! git diff-index --quiet --cached HEAD; then | ||
30 | git commit -m "Automatic commit by the post-save hook" | ||
31 | fi | ||
32 | fi | ||
33 | } | ||
34 | |||
35 | commit_dir "$data_dir" apts todo | ||
36 | commit_dir "$config_dir" conf keys | ||
37 | |||
38 | # Optionally run the CalDAV synchronization script in the background. | ||
39 | cd "$data_dir" || exit | ||
40 | if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then | ||
41 | ( | ||
42 | date="$(date +'%b %d %H:%M:%S')" | ||
43 | echo "$date Running calcurse-caldav from the post-save hook..." | ||
44 | CALCURSE_CALDAV_PASSWORD=$(pass show web/radicale.chudnick.com | head -1) calcurse-caldav | ||
45 | echo | ||
46 | ) >>caldav/log 2>&1 & | ||
47 | fi | ||
diff --git a/.config/calcurse/hooks/pre-load b/.config/calcurse/hooks/pre-load new file mode 100755 index 0000000..dc25771 --- /dev/null +++ b/.config/calcurse/hooks/pre-load | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/bin/sh | ||
2 | [ -d "$HOME/.calcurse" ] && data_dir="$HOME/.calcurse" || data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/calcurse" | ||
3 | |||
4 | cd "$data_dir" || exit | ||
5 | |||
6 | # Do not do anything when synchronizing with a CalDAV server. | ||
7 | [ -f caldav/lock ] && exit | ||
8 | |||
9 | # Run the CalDAV synchronization script in the background. | ||
10 | if [ -d caldav ] && command -v calcurse-caldav >/dev/null; then | ||
11 | ( | ||
12 | date="$(date +'%b %d %H:%M:%S')" | ||
13 | echo "$date Running calcurse-caldav from the pre-load hook..." | ||
14 | CALCURSE_CALDAV_PASSWORD=$(pass web/radicale.chudnick.com | head -1) calcurse-caldav | ||
15 | echo | ||
16 | ) >>caldav/log 2>&1 & | ||
17 | fi | ||