From 767214e4f157ae4a74be0b557bd49e24d972970b Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 7 Jan 2016 18:23:09 +0100 Subject: Add pre-save and post-save hooks This adds support for hooks which are executed before/after saving calcurse data. Hooks can be placed under hooks/pre-save and hooks/post-save in the data directory and need to be executable. Potential use cases include: * Automatically commit any changes to the data files using a VCS. * Automatically sync with some sever component on data file changes. Signed-off-by: Lukas Fleischer --- src/io.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index f12bac9..7411a6b 100644 --- a/src/io.c +++ b/src/io.c @@ -239,6 +239,7 @@ void io_init(const char *cfile, const char *datadir) snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH_NAME, home); snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH_NAME, home); + snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR_NAME, home); } else { home = getenv("HOME"); if (home == NULL) { @@ -252,6 +253,7 @@ void io_init(const char *cfile, const char *datadir) snprintf(path_dpid, BUFSIZ, "%s/" DPID_PATH, home); snprintf(path_dmon_log, BUFSIZ, "%s/" DLOG_PATH, home); snprintf(path_notes, BUFSIZ, "%s/" NOTES_DIR, home); + snprintf(path_hooks, BUFSIZ, "%s/" HOOKS_DIR, home); } if (cfile == NULL) { @@ -391,6 +393,7 @@ void io_save_cal(enum save_display display) if (read_only) return; + run_hook("pre-save"); pthread_mutex_lock(&io_save_mutex); show_bar = 0; @@ -428,6 +431,7 @@ void io_save_cal(enum save_display display) } pthread_mutex_unlock(&io_save_mutex); + run_hook("post-save"); } static void io_load_error(const char *filename, unsigned line, -- cgit v1.2.3-54-g00ecf