commit 19d933bee8ff5d492afef9428f40e73e00ce1b31
parent d74fed41e3885a05b704c677078d335558d08253
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Mon, 4 Jan 2021 21:31:42 +0100
reuse $XDG_CONFIG_HOME
Diffstat:
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/diary.c b/diary.c
@@ -351,10 +351,18 @@ void usage() {
int main(int argc, char** argv) {
setlocale(LC_ALL, "");
char* env_var;
+ char* config_home;
+ char* config_file_path;
chtype atrs;
// the diary directory defaults to the diary_dir specified in the config file
- read_config(CONFIG_FILE_PATH);
+ config_home = getenv("XDG_CONFIG_HOME");
+ if (config_home == NULL) config_home = XDG_CONFIG_HOME_FALLBACK;
+ // concat config home with the file path to the config file
+ config_file_path = (char *) calloc(strlen(config_home) + strlen(CONFIG_FILE_PATH) + 1, sizeof(char));
+ sprintf(config_file_path, "%s/%s", config_home, CONFIG_FILE_PATH);
+ // read config from config file path
+ read_config(config_file_path);
env_var = getenv("DIARY_DIR");
if (env_var != NULL) {
diff --git a/diary.h b/diary.h
@@ -19,7 +19,8 @@
#include <locale.h>
#include <langinfo.h>
-#define CONFIG_FILE_PATH "~/.config/diary/diary.cfg"
+#define XDG_CONFIG_HOME_FALLBACK "~/.config"
+#define CONFIG_FILE_PATH "diary/diary.cfg"
#define DIARY_VERSION "0.4"
#define CAL_WIDTH 21
#define ASIDE_WIDTH 4