Respect XDG environment variables



mc 4.8.1 start to use XDG specification to place their preferences files. But 
why mc don't use XDG environment variables XDG_DATA_HOME, XDG_CACHE_HOME, 
XDG_CONFIG_HOME? These variables intended for overlapping default locations. I 
don't like ".cache", ".config" and similar directly at home directory, so I 
had have done a patch, whcih respect XDG_* environment variables. Use g_getenv 
from glib.

--- lib/mcconfig/paths.c.old    2012-03-19 23:26:22.000000000 +0700
+++ lib/mcconfig/paths.c        2012-05-16 11:59:23.000000000 +0700
@@ -271,21 +271,41 @@
 void
 mc_config_init_config_paths (GError ** error)
 {
-    char *dir;
+    char *dir, *xdgenv;

     if (xdg_vars_initialized)
         return;

 #ifdef MC_HOMEDIR_XDG
+    /* We'll full respect Freedesktop specification              */
+    /* and when XDG_* specified in environment, we'll must use it */
+    xdgenv = g_getenv("XDG_CONFIG_HOME");
+
+    if (xdgenv == NULL || *xdgenv == '\0')
     dir = g_build_filename (mc_config_get_home_dir (), ".config", (char *) 
NULL);
+     else
+      dir = g_build_filename (xdgenv, (char *) NULL);
+
     mc_config_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, 
error);
     g_free (dir);

+    xdgenv = g_getenv("XDG_CACHE_HOME");
+
+    if (xdgenv == NULL || *xdgenv == '\0')
     dir = g_build_filename (mc_config_get_home_dir (), ".cache", (char *) 
NULL);
+     else
+      dir = g_build_filename (xdgenv, (char *) NULL);
+
     mc_cache_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, 
error);
     g_free (dir);

+    xdgenv = g_getenv("XDG_DATA_HOME");
+
+    if (xdgenv == NULL || *xdgenv == '\0')
     dir = g_build_filename (mc_config_get_home_dir (), ".local", "share", 
(char *) NULL);
+     else
+      dir = g_build_filename (xdgenv, "share", (char *) NULL);
+
     mc_data_str = mc_config_init_one_config_path (dir, MC_USERCONF_DIR, 
error);
     g_free (dir);


-- 
   With Best Regards.
   Rashid N. Achilov (RNA1-RIPE), Web: http://openoffice.mirahost.ru
   E-Mail: shelton [гав!] vmfree [тчк] askd [тчк] ru
   PGP: 83 CD E2 A7 37 4A D5 81 D6 D6 52 BF C9 2F 85 AF 97 BE CB 0A



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]