diff --git a/README.md b/README.md index 8ae0084..df64006 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ write your own using `mod.h` if you want to ## config -by default `$XDG_CONFIG_HOME/modfetch.conf` +by default `$XDG_CONFIG_HOME/modfetch.conf`, `~/.config/modfetch.conf` if `$XDG_CONFIG_HOME` doesn't exist format: ``` diff --git a/modfetch.c b/modfetch.c index 297a520..d1134ea 100644 --- a/modfetch.c +++ b/modfetch.c @@ -211,8 +211,16 @@ Config parse_config(FILE *config_file) { int main(int argc, char *argv[]) { char *config_path; + char *config_dir = getenv("XDG_CONFIG_HOME"); + if (config_dir == NULL) { + char *home = getenv("$HOME"); + if (asprintf(&config_dir, "%s/.config", home) < 0) { + fprintf(stderr, "error: failed formatting config dir (this shouldn't happen)"); + exit(EXIT_FAILURE); + } + } - if (asprintf(&config_path, "%s/modfetch.conf", getenv("XDG_CONFIG_HOME")) < 0) { + if (asprintf(&config_path, "%s/modfetch.conf", config_dir) < 0) { fprintf(stderr, "error: failed formatting config path (this shouldn't happen)"); exit(EXIT_FAILURE); }