Add support for 'rem' for the XDG Base Directory Specification [1], specifically the environment variable XDG_CONFIG_HOME as default file.
XDG_CONFIG_HOME gives us a alternative to littering our home directory with dotfiles. Instead all these user configuration files are stored in a user specified or in the xdg default, "$HOME/.config", directory. After convention I have used the program name, 'remind', as subfolder and the filename, 'reminders', is the dotfile filename minus the leading dot. This gives us either "$XDG_CONFIG_HOME/remind/reminders" when XDG_CONFIG_HOME is set, or "$HOME/.config/remind/reminders" when it is not. If this file does not exist or is not readable it defaults back to the current default: "$HOME/.reminders". This is fully backwards compatible. [1]: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html Signed-off-by: Rolf Morel <[email protected]> --- src/init.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/init.c b/src/init.c index 35256ce..dfb0c2c 100644 --- a/src/init.c +++ b/src/init.c @@ -101,7 +101,7 @@ static DynamicBuffer default_filename_buf; /***************************************************************/ static char const *DefaultFilename(void) { - char const *s; + char const *s, *xdg; DBufInit(&default_filename_buf); @@ -115,6 +115,23 @@ static char const *DefaultFilename(void) fprintf(stderr, "HOME environment variable not set. Unable to determine reminder file.\n"); exit(1); } + + xdg = getenv("XDG_CONFIG_HOME"); + if (xdg) + DBufPuts(&default_filename_buf, xdg); + else { + /* Use xdg default "$HOME/.config". */ + DBufPuts(&default_filename_buf, s); + DBufPuts(&default_filename_buf, "/.config"); + } + + DBufPuts(&default_filename_buf, "/remind/reminders"); + + if (access(DBufValue(&default_filename_buf), R_OK) == 0) + return DBufValue(&default_filename_buf); + + DBufFree(&default_filename_buf); + DBufPuts(&default_filename_buf, s); DBufPuts(&default_filename_buf, "/.reminders"); return DBufValue(&default_filename_buf); -- 1.8.4 _______________________________________________ Remind-fans mailing list [email protected] http://lists.roaringpenguin.com/cgi-bin/mailman/listinfo/remind-fans Remind is at http://www.roaringpenguin.com/products/remind
