Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
allow placing calfrc under $XDG_CONFIG_HOME
- first check if ~/.calfrc exists, if it does use it

- otherwise attempt to create $XDG_CONFIG_HOME/calf/ if it does not
  exist

- if the folder now exists use as path $XDG_CONFIG_HOME/calf/calfrc,
  otherwise fall back to ~/.calfrc
  • Loading branch information
circled-square committed Jun 19, 2023
commit d7abf2b60fa074cfb0249b618ba7aa0380794496
29 changes: 26 additions & 3 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <iostream>

#include <sys/stat.h>

using namespace calf_plugins;
using namespace std;

Expand Down Expand Up @@ -502,10 +504,31 @@ bool window_update_controller::check_redraw(GtkWidget *toplevel)
gui_environment::gui_environment()
{
keyfile = g_key_file_new();

string filename;

gchar *fn = g_build_filename(getenv("HOME"), ".calfrc", NULL);
string filename = fn;
g_free(fn);
gchar *fn_under_home = g_build_filename(getenv("HOME"), ".calfrc", NULL);
char *xdg_conf = getenv("XDG_CONFIG_HOME");
gchar *calf_conf_dir = g_build_filename(xdg_conf, "calf", NULL);
gchar *fn_under_conf = g_build_filename(calf_conf_dir, "calfrc", NULL);

//if $HOME/.calfrc exists or XDG_CONFIG_HOME is not set use $HOME/.calfrc
if(g_file_test(fn_under_home, G_FILE_TEST_IS_REGULAR) || xdg_conf == NULL) {
filename = fn_under_home;
} else {
//if $XDG_CONFIG_HOME/calf does not exist, create it
mkdir(calf_conf_dir, 0644);

if(g_file_test(calf_conf_dir, G_FILE_TEST_IS_DIR))
filename = fn_under_conf;
else
filename = fn_under_home; //failed creating directory: fall back to $HOME/.calfrc
}

g_free(calf_conf_dir);
g_free(fn_under_conf);
g_free(fn_under_home);

g_key_file_load_from_file(keyfile, filename.c_str(), (GKeyFileFlags)(G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS), NULL);

config_db = new calf_utils::gkeyfile_config_db(keyfile, filename.c_str(), "gui");
Expand Down