You are not logged in.

#26 2009-08-10 09:40:12

Shapeshifter
Member
Registered: 2008-03-11
Posts: 224

Re: Put your $HOME in .home!

SpeedVin wrote:

I got one question about bash.
Bash use config's from /home/user or /home/user/.home can I delate them form my /home/user?

You mean .bashrc? Any app will now use the .home directory to look for config files, so you will have to move all your configs to the /home/user/.home directory, and you need none in /home/user.

Offline

#27 2009-08-10 10:12:46

SpeedVin
Member
From: Poland
Registered: 2009-04-29
Posts: 955

Re: Put your $HOME in .home!

Shapeshifter wrote:
SpeedVin wrote:

I got one question about bash.
Bash use config's from /home/user or /home/user/.home can I delate them form my /home/user?

You mean .bashrc? Any app will now use the .home directory to look for config files, so you will have to move all your configs to the /home/user/.home directory, and you need none in /home/user.

I moved my all config's to $HOME/.home with .bashc and so long but stay with bash config's in $HOME to backup wink
Ok I will delate backup's wink
Thanks


Shell Scripter | C/C++/Python/Java Coder | ZSH

Offline

#28 2009-08-10 11:34:43

iphitus
Forum Fellow
From: Melbourne, Australia
Registered: 2004-10-09
Posts: 4,927

Re: Put your $HOME in .home!

scj wrote:

Or you could try something like libetc

AWESOME.

Offline

#29 2009-08-10 13:28:15

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Put your $HOME in .home!

scj wrote:

Or you could try something like libetc

That looks wonderful, but it treats all dotfiles as configuration. So I've started writing a patch to allow some files (controlled by $LIBETC_CACHE and $LIBETC_DATA) to be located in $XDG_CACHE_HOME and $XDG_DATA_HOME.

Offline

#30 2009-08-10 17:37:36

jceasless
Member
Registered: 2009-04-20
Posts: 73

Re: Put your $HOME in .home!

Barrucadu wrote:
scj wrote:

Or you could try something like libetc

That looks wonderful, but it treats all dotfiles as configuration. So I've started writing a patch to allow some files (controlled by $LIBETC_CACHE and $LIBETC_DATA) to be located in $XDG_CACHE_HOME and $XDG_DATA_HOME.

When good things get better smile

Offline

#31 2009-08-10 18:08:33

thayer
Fellow
From: Vancouver, BC
Registered: 2007-05-20
Posts: 1,560
Website

Re: Put your $HOME in .home!

Maybe I'm missing the point, but what's the difference between having 100 disorganized dotfiles sitting in /home/$USER vs. sitting in /home/$USER/.home?  I mean, I don't actually *see* the dotfiles unless I choose to view hidden files, in which case there's no difference between ~ or ~/.home.


thayer williams ~ cinderwick.ca

Offline

#32 2009-08-10 19:00:45

ugkbunb
Member
Registered: 2009-02-26
Posts: 227

Re: Put your $HOME in .home!

^^
I imagine many people like me just leave show hidden files on.

Offline

#33 2009-08-10 19:02:58

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Put your $HOME in .home!

thayer wrote:

Maybe I'm missing the point, but what's the difference between having 100 disorganized dotfiles sitting in /home/$USER vs. sitting in /home/$USER/.home?  I mean, I don't actually *see* the dotfiles unless I choose to view hidden files, in which case there's no difference between ~ or ~/.home.

Dual-booters have to navigate through 300 dotfiles to get to anything in Windows, Acme doesn't hide them, and it's a mess in general.

Offline

#34 2009-08-11 17:17:05

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Put your $HOME in .home!

jceasless wrote:
Barrucadu wrote:
scj wrote:

Or you could try something like libetc

That looks wonderful, but it treats all dotfiles as configuration. So I've started writing a patch to allow some files (controlled by $LIBETC_CACHE and $LIBETC_DATA) to be located in $XDG_CACHE_HOME and $XDG_DATA_HOME.

When good things get better smile

Even better, I added a $LIBETC_IGNORE variable as well, and it seems to be working:

data_cache_ignore.patch:

*** libetc-old.c    2008-01-27 20:35:04.000000000 +0000
--- libetc.c    2009-08-11 17:35:29.417682155 +0100
***************
*** 77,90 ****
  static int (*orig_mkstemp) (char *template);
  static int (*orig_mkstemp64) (char *template);
  
! static char *ETCDIR = ".config";
! static char *orig, *home, *etcdir;
  static int started = 0;
  static int blacklisted = 0;
  
  // is the running exec blacklisted ?
  static void am_i_blacklisted () {
!     char running_exec[4096], *exec_blacklist, *str;
      int len;
  
      if ((len = orig_readlink ("/proc/self/exe", running_exec, sizeof (running_exec) - 1))) {
--- 77,113 ----
  static int (*orig_mkstemp) (char *template);
  static int (*orig_mkstemp64) (char *template);
  
! static char *CONFIGDIR = ".config";
! static char *DATADIR = ".local/share";
! static char *CACHEDIR = ".cache";
! static char *orig, *home, *etcdir, *data_files, *cache_files, *ignored_files;
  static int started = 0;
  static int blacklisted = 0;
  
+ // is the speicified text in the list?
+ static int am_i_in_list (const char *text, const char *list, int exact) {
+     char *token;
+ 
+     token = strtok(strdup(list), ":");
+     while (token != NULL) {
+         if(exact == 1 && strcmp(token, text) == 0) {
+         return 1;
+     } else if(exact == 0 && (strncmp(token, text, strlen(text)) == 0 || strncmp(token, text, strlen(token)) == 0)) {
+       PRINT_DEBUG("%s %s YES!\n", text, token);
+         return 1;
+     } else {
+       PRINT_DEBUG("%s %s NO!\n", text, token);
+     }
+ 
+     token = strtok(NULL, ":");
+     }
+ 
+     return 0;
+ }
+ 
  // is the running exec blacklisted ?
  static void am_i_blacklisted () {
!     char running_exec[4096], *exec_blacklist;
      int len;
  
      if ((len = orig_readlink ("/proc/self/exe", running_exec, sizeof (running_exec) - 1))) {
***************
*** 92,129 ****
          PRINT_DEBUG ("running exec: %s\n", running_exec);
          if ((exec_blacklist = getenv ("LIBETC_BLACKLIST"))) {
              PRINT_DEBUG ("blacklist: %s\n", exec_blacklist);
!             while ((str = strrchr (exec_blacklist, ':'))) {
!                 if (0 == strcmp (++str, running_exec)) {
!                     blacklisted = 1;
!                     PRINT_DEBUG ("I am blacklisted !\n");
!                 }
!                 str--;
!                 str[0] = '\0';
!             }
!             if (0 == strcmp (exec_blacklist, running_exec)) {
!                 blacklisted = 1;
!                 PRINT_DEBUG ("I am blacklisted !\n");
              }
          }
      }
  }
  
  // find where to put the dotfiles
! static void find_etcdir () {
!     char *etc, *xdg_config_home;
  
!     if (!(xdg_config_home = getenv ("XDG_CONFIG_HOME"))) {
!         if (!(etc = getenv ("ETC"))) {
!             etc = ETCDIR;
!             PRINT_DEBUG("default value: %s\n", etc);
!         }
!         PRINT_DEBUG("$ETC: %s\n", etc);
!         etcdir = malloc (strlen (home) + strlen (etc) + 1);
!         sprintf (etcdir, "%s/%s", home, etc);
!     } else {
!         PRINT_DEBUG("$XDG_CONFIG_HOME: %s\n", xdg_config_home);
!         etcdir = xdg_config_home;
!     }
  }
  
  // mkdir etcdir if it does not exist
--- 115,205 ----
          PRINT_DEBUG ("running exec: %s\n", running_exec);
          if ((exec_blacklist = getenv ("LIBETC_BLACKLIST"))) {
              PRINT_DEBUG ("blacklist: %s\n", exec_blacklist);
!             if (am_i_in_list (running_exec, exec_blacklist, 1)) {
!               blacklisted = 1;
!               PRINT_DEBUG ("I am blacklisted !\n");
              }
          }
      }
  }
  
+ // where does the file go?
+ static int where_am_i (const char* filename) {
+     // 0 = config
+     // 1 = data
+     // 2 = cache
+     // 3 = ignore
+ 
+     int returntype = 0;
+ 
+     if (data_files && am_i_in_list (filename, data_files, 0)) {
+         returntype = 1;
+         PRINT_DEBUG ("I am data !\n");
+     } else if (cache_files && am_i_in_list (filename, cache_files, 0)) {
+         returntype = 2;
+         PRINT_DEBUG ("I am cache !\n");
+     } else if (ignored_files && am_i_in_list (filename, ignored_files, 0)) {
+         returntype = 3;
+         PRINT_DEBUG ("I am ignored !\n");
+     }
+ 
+ 
+     return returntype;
+ }
+ 
  // find where to put the dotfiles
! static void find_etcdir (int type, int initial) {
!     char *etc, *xdg_dir;
  
!     if(type == 0) {
!         if (!(xdg_dir = getenv ("XDG_CONFIG_HOME"))) {
!             if (!(etc = getenv ("ETC"))) {
!                 etc = CONFIGDIR;
!                 PRINT_DEBUG("default value: %s\n", etc);
!             }
!             PRINT_DEBUG("$ETC: %s\n", etc);
!             etcdir = malloc (strlen (home) + strlen (etc) + 1);
!             sprintf (etcdir, "%s/%s", home, etc);
!         } else {
!             PRINT_DEBUG("$XDG_CONFIG_HOME: %s\n", xdg_dir);
!             etcdir = xdg_dir;
!         }
!         if(initial == 1){
!             CONFIGDIR = strdup(etcdir);
!         }
!     } else if(type == 1){
!         if (!(xdg_dir = getenv ("XDG_DATA_HOME"))) {
!             if (!(etc = getenv ("ETC"))) {
!                 etc = DATADIR;
!                 PRINT_DEBUG("default value: %s\n", etc);
!             }
!             PRINT_DEBUG("$ETC: %s\n", etc);
!             etcdir = malloc (strlen (home) + strlen (etc) + 1);
!             sprintf (etcdir, "%s/%s", home, etc);
!         } else {
!             PRINT_DEBUG("$XDG_DATA_HOME: %s\n", xdg_dir);
!             etcdir = xdg_dir;
!         }
!         if(initial == 1){
!             DATADIR = strdup(etcdir);
!         }
!     } else if(type == 2){
!         if (!(xdg_dir = getenv ("XDG_CACHE_HOME"))) {
!             if (!(etc = getenv ("ETC"))) {
!                 etc = CACHEDIR;
!                 PRINT_DEBUG("default value: %s\n", etc);
!             }
!             PRINT_DEBUG("$ETC: %s\n", etc);
!             etcdir = malloc (strlen (home) + strlen (etc) + 1);
!             sprintf (etcdir, "%s/%s", home, etc);
!         } else {
!             PRINT_DEBUG("$XDG_CACHE_HOME: %s\n", xdg_dir);
!             etcdir = xdg_dir;
!         }
!         if(initial == 1){
!             CACHEDIR = strdup(etcdir);
!         }
!     }
  }
  
  // mkdir etcdir if it does not exist
***************
*** 222,234 ****
      orig = malloc (strlen (home) + 3);
      sprintf (orig, "%s/.", home);
  
!     find_etcdir ();
      mkdir_etcdir (etcdir);
  #ifdef XAUTH_HACK
      xauthority_hack (etcdir);
  #endif
  
!     PRINT_DEBUG("etcdir: %s\n", etcdir);
      started = 1;
  }
  
--- 298,322 ----
      orig = malloc (strlen (home) + 3);
      sprintf (orig, "%s/.", home);
  
!     data_files = getenv ("LIBETC_DATA");
!     cache_files = getenv ("LIBETC_CACHE");
!     ignored_files = getenv ("LIBETC_IGNORE");
!     PRINT_DEBUG ("data files: %s\n", data_files);
!     PRINT_DEBUG ("cache files: %s\n", cache_files);
!     PRINT_DEBUG ("ignored files: %s\n", ignored_files);
! 
!     find_etcdir (0, 1);
      mkdir_etcdir (etcdir);
  #ifdef XAUTH_HACK
      xauthority_hack (etcdir);
  #endif
  
!     find_etcdir (1, 1);
!     mkdir_etcdir (etcdir);
! 
!     find_etcdir (2, 1);
!     mkdir_etcdir (etcdir);
! 
      started = 1;
  }
  
***************
*** 247,277 ****
  
      wd = get_current_dir_name ();
  
!     if ((0 == strcmp (wd, home)) // if cwd == $HOME
!         && filename [0] == '.'   // and a dotfile
!         && (0 != strcmp (filename, "."))
!         && (0 != strncmp (filename, "./", 2))
!         && (0 != strncmp (filename, "..", 2))) {
!         char tmpfilename [strlen (home) + strlen (filename) + 2];
!         sprintf (tmpfilename, "%s/%s", home, filename);
!         if (0 == strncmp (tmpfilename, etcdir, strlen(etcdir))) { // do not translate if trying to read/write in $XDG_CONFIG_HOME
!             newfilename = strdup (filename);
!         } else {
!             filename++; // remove the dot
              newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
              sprintf (newfilename, "%s/%s", etcdir, filename);
              PRINT_DEBUG("RENAMED IN $HOME --> %s\n", newfilename);
          }
!     } else if (0 == strncmp (filename, orig, strlen (orig)) // if file name is $HOME/.something
!            && 0!= strncmp (filename, etcdir, strlen (etcdir)) ) { // do not translate if trying to read/write in $XDG_CONFIG_HOME
!         filename += strlen (home) + 2; // remove "$HOME/." from the filename
!         newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
!         sprintf (newfilename, "%s/%s", etcdir, filename);
!         PRINT_DEBUG("RENAMED --> %s\n", newfilename);
      } else { // not a dotfile
!         newfilename = strdup (filename);
      }
!     
      free (wd);
      return newfilename;
  }
--- 335,382 ----
  
      wd = get_current_dir_name ();
  
!     if ((0 == strcmp (wd, home) && filename [0] == '.') || 0 == strncmp (filename, orig, strlen (orig))){
!         int filetype = where_am_i(filename);
!     
!         if(filetype != 3){
!             find_etcdir(filetype, 0);
!           
!         if ((0 == strcmp (wd, home)) // if cwd == $HOME
!             && filename [0] == '.'   // and a dotfile
!             && (0 != strcmp (filename, "."))
!             && (0 != strncmp (filename, "./", 2))
!             && (0 != strncmp (filename, "..", 2))) {
!           
!             char tmpfilename [strlen (home) + strlen (filename) + 2];
!             sprintf (tmpfilename, "%s/%s", home, filename);
!             if (0 == strncmp (tmpfilename, CONFIGDIR, strlen(CONFIGDIR))
!             || 0 == strncmp (tmpfilename, DATADIR, strlen(DATADIR))
!             || 0 == strncmp (tmpfilename, CACHEDIR, strlen(CACHEDIR))) { // do not translate if trying to read/write in $XDG_CONFIG/DATA/CACHE_HOME
!                         newfilename = strdup (filename);
!             } else {
!                 filename++; // remove the dot
              newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
              sprintf (newfilename, "%s/%s", etcdir, filename);
              PRINT_DEBUG("RENAMED IN $HOME --> %s\n", newfilename);
+             }
+         } else if (0 == strncmp (filename, orig, strlen (orig)) // if file name is $HOME/.something
+                && (0!= strncmp (filename, CONFIGDIR, strlen (CONFIGDIR))
+                    && 0!= strncmp (filename, DATADIR, strlen (DATADIR))
+                    && 0!= strncmp (filename, CACHEDIR, strlen (CACHEDIR)))) { // do not translate if trying to read/write in $XDG_CONFIG/DATA/CACHE_HOME
+             filename += strlen (home) + 2; // remove "$HOME/." from the filename
+             newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
+             sprintf (newfilename, "%s/%s", etcdir, filename);
+             PRINT_DEBUG("RENAMED --> %s\n", newfilename);
+         } else { // not a dotfile
+             newfilename = strdup (filename);
          }
!         } else { // not a dotfile
!           newfilename = strdup (filename);
!         }
      } else { // not a dotfile
!         newfilename = strdup (filename);
      }
!     
      free (wd);
      return newfilename;
  }

Offline

#35 2009-08-11 22:06:02

Ranguvar
Member
Registered: 2008-08-12
Posts: 2,540

Re: Put your $HOME in .home!

Holy shit, Batman! libetc with this patch sounds awesome. I'll try it soon and post back.

Excellent work, Barrucadu! Thanks _very_ much. I can see a lot of users finding a use for this.

Offline

#36 2009-08-13 03:49:09

ugkbunb
Member
Registered: 2009-02-26
Posts: 227

Re: Put your $HOME in .home!

I tried installing libetc... I followed the instructions from the website... now when I reboot all the config files are moved to the appropriate folder... however compiz/xfce/urxvt/anything that relied on those config files resort to their default config.

Offline

#37 2009-09-15 06:54:36

ugkbunb
Member
Registered: 2009-02-26
Posts: 227

Re: Put your $HOME in .home!

bump -- anyone else experiencing the behavior I mentioned above?

Offline

#38 2009-09-15 07:04:00

Barrucadu
Member
From: York, England
Registered: 2008-03-30
Posts: 1,158
Website

Re: Put your $HOME in .home!

ugkbunb wrote:

I tried installing libetc... I followed the instructions from the website... now when I reboot all the config files are moved to the appropriate folder... however compiz/xfce/urxvt/anything that relied on those config files resort to their default config.

Try copying your old config files to the new location, I think I had a problem with preserving configuration automatically.

Offline

#39 2009-09-15 18:21:54

smartboyathome
Member
From: $HOME
Registered: 2007-12-23
Posts: 334
Website

Re: Put your $HOME in .home!

Barrucadu wrote:
jceasless wrote:
Barrucadu wrote:

That looks wonderful, but it treats all dotfiles as configuration. So I've started writing a patch to allow some files (controlled by $LIBETC_CACHE and $LIBETC_DATA) to be located in $XDG_CACHE_HOME and $XDG_DATA_HOME.

When good things get better smile

Even better, I added a $LIBETC_IGNORE variable as well, and it seems to be working:

data_cache_ignore.patch:

*** libetc-old.c    2008-01-27 20:35:04.000000000 +0000
--- libetc.c    2009-08-11 17:35:29.417682155 +0100
***************
*** 77,90 ****
  static int (*orig_mkstemp) (char *template);
  static int (*orig_mkstemp64) (char *template);
  
! static char *ETCDIR = ".config";
! static char *orig, *home, *etcdir;
  static int started = 0;
  static int blacklisted = 0;
  
  // is the running exec blacklisted ?
  static void am_i_blacklisted () {
!     char running_exec[4096], *exec_blacklist, *str;
      int len;
  
      if ((len = orig_readlink ("/proc/self/exe", running_exec, sizeof (running_exec) - 1))) {
--- 77,113 ----
  static int (*orig_mkstemp) (char *template);
  static int (*orig_mkstemp64) (char *template);
  
! static char *CONFIGDIR = ".config";
! static char *DATADIR = ".local/share";
! static char *CACHEDIR = ".cache";
! static char *orig, *home, *etcdir, *data_files, *cache_files, *ignored_files;
  static int started = 0;
  static int blacklisted = 0;
  
+ // is the speicified text in the list?
+ static int am_i_in_list (const char *text, const char *list, int exact) {
+     char *token;
+ 
+     token = strtok(strdup(list), ":");
+     while (token != NULL) {
+         if(exact == 1 && strcmp(token, text) == 0) {
+         return 1;
+     } else if(exact == 0 && (strncmp(token, text, strlen(text)) == 0 || strncmp(token, text, strlen(token)) == 0)) {
+       PRINT_DEBUG("%s %s YES!\n", text, token);
+         return 1;
+     } else {
+       PRINT_DEBUG("%s %s NO!\n", text, token);
+     }
+ 
+     token = strtok(NULL, ":");
+     }
+ 
+     return 0;
+ }
+ 
  // is the running exec blacklisted ?
  static void am_i_blacklisted () {
!     char running_exec[4096], *exec_blacklist;
      int len;
  
      if ((len = orig_readlink ("/proc/self/exe", running_exec, sizeof (running_exec) - 1))) {
***************
*** 92,129 ****
          PRINT_DEBUG ("running exec: %s\n", running_exec);
          if ((exec_blacklist = getenv ("LIBETC_BLACKLIST"))) {
              PRINT_DEBUG ("blacklist: %s\n", exec_blacklist);
!             while ((str = strrchr (exec_blacklist, ':'))) {
!                 if (0 == strcmp (++str, running_exec)) {
!                     blacklisted = 1;
!                     PRINT_DEBUG ("I am blacklisted !\n");
!                 }
!                 str--;
!                 str[0] = '\0';
!             }
!             if (0 == strcmp (exec_blacklist, running_exec)) {
!                 blacklisted = 1;
!                 PRINT_DEBUG ("I am blacklisted !\n");
              }
          }
      }
  }
  
  // find where to put the dotfiles
! static void find_etcdir () {
!     char *etc, *xdg_config_home;
  
!     if (!(xdg_config_home = getenv ("XDG_CONFIG_HOME"))) {
!         if (!(etc = getenv ("ETC"))) {
!             etc = ETCDIR;
!             PRINT_DEBUG("default value: %s\n", etc);
!         }
!         PRINT_DEBUG("$ETC: %s\n", etc);
!         etcdir = malloc (strlen (home) + strlen (etc) + 1);
!         sprintf (etcdir, "%s/%s", home, etc);
!     } else {
!         PRINT_DEBUG("$XDG_CONFIG_HOME: %s\n", xdg_config_home);
!         etcdir = xdg_config_home;
!     }
  }
  
  // mkdir etcdir if it does not exist
--- 115,205 ----
          PRINT_DEBUG ("running exec: %s\n", running_exec);
          if ((exec_blacklist = getenv ("LIBETC_BLACKLIST"))) {
              PRINT_DEBUG ("blacklist: %s\n", exec_blacklist);
!             if (am_i_in_list (running_exec, exec_blacklist, 1)) {
!               blacklisted = 1;
!               PRINT_DEBUG ("I am blacklisted !\n");
              }
          }
      }
  }
  
+ // where does the file go?
+ static int where_am_i (const char* filename) {
+     // 0 = config
+     // 1 = data
+     // 2 = cache
+     // 3 = ignore
+ 
+     int returntype = 0;
+ 
+     if (data_files && am_i_in_list (filename, data_files, 0)) {
+         returntype = 1;
+         PRINT_DEBUG ("I am data !\n");
+     } else if (cache_files && am_i_in_list (filename, cache_files, 0)) {
+         returntype = 2;
+         PRINT_DEBUG ("I am cache !\n");
+     } else if (ignored_files && am_i_in_list (filename, ignored_files, 0)) {
+         returntype = 3;
+         PRINT_DEBUG ("I am ignored !\n");
+     }
+ 
+ 
+     return returntype;
+ }
+ 
  // find where to put the dotfiles
! static void find_etcdir (int type, int initial) {
!     char *etc, *xdg_dir;
  
!     if(type == 0) {
!         if (!(xdg_dir = getenv ("XDG_CONFIG_HOME"))) {
!             if (!(etc = getenv ("ETC"))) {
!                 etc = CONFIGDIR;
!                 PRINT_DEBUG("default value: %s\n", etc);
!             }
!             PRINT_DEBUG("$ETC: %s\n", etc);
!             etcdir = malloc (strlen (home) + strlen (etc) + 1);
!             sprintf (etcdir, "%s/%s", home, etc);
!         } else {
!             PRINT_DEBUG("$XDG_CONFIG_HOME: %s\n", xdg_dir);
!             etcdir = xdg_dir;
!         }
!         if(initial == 1){
!             CONFIGDIR = strdup(etcdir);
!         }
!     } else if(type == 1){
!         if (!(xdg_dir = getenv ("XDG_DATA_HOME"))) {
!             if (!(etc = getenv ("ETC"))) {
!                 etc = DATADIR;
!                 PRINT_DEBUG("default value: %s\n", etc);
!             }
!             PRINT_DEBUG("$ETC: %s\n", etc);
!             etcdir = malloc (strlen (home) + strlen (etc) + 1);
!             sprintf (etcdir, "%s/%s", home, etc);
!         } else {
!             PRINT_DEBUG("$XDG_DATA_HOME: %s\n", xdg_dir);
!             etcdir = xdg_dir;
!         }
!         if(initial == 1){
!             DATADIR = strdup(etcdir);
!         }
!     } else if(type == 2){
!         if (!(xdg_dir = getenv ("XDG_CACHE_HOME"))) {
!             if (!(etc = getenv ("ETC"))) {
!                 etc = CACHEDIR;
!                 PRINT_DEBUG("default value: %s\n", etc);
!             }
!             PRINT_DEBUG("$ETC: %s\n", etc);
!             etcdir = malloc (strlen (home) + strlen (etc) + 1);
!             sprintf (etcdir, "%s/%s", home, etc);
!         } else {
!             PRINT_DEBUG("$XDG_CACHE_HOME: %s\n", xdg_dir);
!             etcdir = xdg_dir;
!         }
!         if(initial == 1){
!             CACHEDIR = strdup(etcdir);
!         }
!     }
  }
  
  // mkdir etcdir if it does not exist
***************
*** 222,234 ****
      orig = malloc (strlen (home) + 3);
      sprintf (orig, "%s/.", home);
  
!     find_etcdir ();
      mkdir_etcdir (etcdir);
  #ifdef XAUTH_HACK
      xauthority_hack (etcdir);
  #endif
  
!     PRINT_DEBUG("etcdir: %s\n", etcdir);
      started = 1;
  }
  
--- 298,322 ----
      orig = malloc (strlen (home) + 3);
      sprintf (orig, "%s/.", home);
  
!     data_files = getenv ("LIBETC_DATA");
!     cache_files = getenv ("LIBETC_CACHE");
!     ignored_files = getenv ("LIBETC_IGNORE");
!     PRINT_DEBUG ("data files: %s\n", data_files);
!     PRINT_DEBUG ("cache files: %s\n", cache_files);
!     PRINT_DEBUG ("ignored files: %s\n", ignored_files);
! 
!     find_etcdir (0, 1);
      mkdir_etcdir (etcdir);
  #ifdef XAUTH_HACK
      xauthority_hack (etcdir);
  #endif
  
!     find_etcdir (1, 1);
!     mkdir_etcdir (etcdir);
! 
!     find_etcdir (2, 1);
!     mkdir_etcdir (etcdir);
! 
      started = 1;
  }
  
***************
*** 247,277 ****
  
      wd = get_current_dir_name ();
  
!     if ((0 == strcmp (wd, home)) // if cwd == $HOME
!         && filename [0] == '.'   // and a dotfile
!         && (0 != strcmp (filename, "."))
!         && (0 != strncmp (filename, "./", 2))
!         && (0 != strncmp (filename, "..", 2))) {
!         char tmpfilename [strlen (home) + strlen (filename) + 2];
!         sprintf (tmpfilename, "%s/%s", home, filename);
!         if (0 == strncmp (tmpfilename, etcdir, strlen(etcdir))) { // do not translate if trying to read/write in $XDG_CONFIG_HOME
!             newfilename = strdup (filename);
!         } else {
!             filename++; // remove the dot
              newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
              sprintf (newfilename, "%s/%s", etcdir, filename);
              PRINT_DEBUG("RENAMED IN $HOME --> %s\n", newfilename);
          }
!     } else if (0 == strncmp (filename, orig, strlen (orig)) // if file name is $HOME/.something
!            && 0!= strncmp (filename, etcdir, strlen (etcdir)) ) { // do not translate if trying to read/write in $XDG_CONFIG_HOME
!         filename += strlen (home) + 2; // remove "$HOME/." from the filename
!         newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
!         sprintf (newfilename, "%s/%s", etcdir, filename);
!         PRINT_DEBUG("RENAMED --> %s\n", newfilename);
      } else { // not a dotfile
!         newfilename = strdup (filename);
      }
!     
      free (wd);
      return newfilename;
  }
--- 335,382 ----
  
      wd = get_current_dir_name ();
  
!     if ((0 == strcmp (wd, home) && filename [0] == '.') || 0 == strncmp (filename, orig, strlen (orig))){
!         int filetype = where_am_i(filename);
!     
!         if(filetype != 3){
!             find_etcdir(filetype, 0);
!           
!         if ((0 == strcmp (wd, home)) // if cwd == $HOME
!             && filename [0] == '.'   // and a dotfile
!             && (0 != strcmp (filename, "."))
!             && (0 != strncmp (filename, "./", 2))
!             && (0 != strncmp (filename, "..", 2))) {
!           
!             char tmpfilename [strlen (home) + strlen (filename) + 2];
!             sprintf (tmpfilename, "%s/%s", home, filename);
!             if (0 == strncmp (tmpfilename, CONFIGDIR, strlen(CONFIGDIR))
!             || 0 == strncmp (tmpfilename, DATADIR, strlen(DATADIR))
!             || 0 == strncmp (tmpfilename, CACHEDIR, strlen(CACHEDIR))) { // do not translate if trying to read/write in $XDG_CONFIG/DATA/CACHE_HOME
!                         newfilename = strdup (filename);
!             } else {
!                 filename++; // remove the dot
              newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
              sprintf (newfilename, "%s/%s", etcdir, filename);
              PRINT_DEBUG("RENAMED IN $HOME --> %s\n", newfilename);
+             }
+         } else if (0 == strncmp (filename, orig, strlen (orig)) // if file name is $HOME/.something
+                && (0!= strncmp (filename, CONFIGDIR, strlen (CONFIGDIR))
+                    && 0!= strncmp (filename, DATADIR, strlen (DATADIR))
+                    && 0!= strncmp (filename, CACHEDIR, strlen (CACHEDIR)))) { // do not translate if trying to read/write in $XDG_CONFIG/DATA/CACHE_HOME
+             filename += strlen (home) + 2; // remove "$HOME/." from the filename
+             newfilename = malloc (strlen (filename) + strlen (etcdir) + 2);
+             sprintf (newfilename, "%s/%s", etcdir, filename);
+             PRINT_DEBUG("RENAMED --> %s\n", newfilename);
+         } else { // not a dotfile
+             newfilename = strdup (filename);
          }
!         } else { // not a dotfile
!           newfilename = strdup (filename);
!         }
      } else { // not a dotfile
!         newfilename = strdup (filename);
      }
!     
      free (wd);
      return newfilename;
  }

What kind of patch is that? I can't get it to work with the normal patch util.

Offline

#40 2010-02-24 11:07:27

tzervo
Member
From: Athens
Registered: 2009-04-03
Posts: 86

Re: Put your $HOME in .home!

For using shapeshifter's tactic (move $HOME to .home), zsh users can alias -g ~~="/home/$USER" and still be able to somewhat use ~ (not perfect but ... :-) )

Offline

#41 2010-02-24 15:46:37

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Put your $HOME in .home!

I don't bother with this. I let my home directory get trashed and keep my data files elsewhere (/n or whatever). Advantage: my data resides on a separate partition and is not bound to any one OS.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#42 2010-02-24 17:55:16

N30N
Member
Registered: 2007-04-08
Posts: 273

Re: Put your $HOME in .home!

Since this got bumped…

smartboyathome wrote:

What kind of patch is that? I can't get it to work with the normal patch util.

The indentation got messed up, here's a working copy: data_cache_ignore.patch.

@Barrucadu,
Did you submit this awesome patch upstream? smile

Offline

#43 2010-02-24 18:06:39

jowilkin
Member
Registered: 2009-05-07
Posts: 243

Re: Put your $HOME in .home!

How can you not be a ~ user?????  It's so useful...

Offline

#44 2010-02-24 18:21:48

jhvid
Member
From: /dev/denmark
Registered: 2009-08-19
Posts: 52

Re: Put your $HOME in .home!

jowilkin wrote:

How can you not be a ~ user?????  It's so useful...

With

alias data="cd /home/user/data"
# and
export DATA="/home/user/data"

GCS d- s-:+ a12 C++++ U++++ L+++ P--- E--- W+++ N+ o K- w--- O? M-- V? PS PE
Y- PGP? t? 5? X? R tv b+++ DI+ D- G++ e++ h! !r !y

Please ignore me... I'm pretty weird...

Offline

#45 2010-02-24 18:33:18

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: Put your $HOME in .home!

I support this change; any software I make will store its config in $XDG_CONFIG_HOME.

If anyone is interested, we could get with the Arch devs and start this migration; it would better adhere to the Free Desktop Standards, would it not?

Offline

#46 2010-02-24 19:48:44

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: Put your $HOME in .home!

By default? Hell no.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#47 2010-02-24 22:09:16

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: Put your $HOME in .home!

smartboyathome wrote:
Barrucadu wrote:

(…) I added a $LIBETC_IGNORE variable as well, and it seems to be working:

data_cache_ignore.patch:

What kind of patch is that? I can't get it to work with the normal patch util.

It's a context diff. I tried to apply this to the AUR libetc package, and it failed due to the two other patches already having been applied, so I patched this thing manually and made a unified diff outta it:

diff -u libetc-0.4.old/libetc.c libetc-0.4.new/libetc.c
--- libetc-0.4.old/libetc.c    2010-02-24 22:39:45.392744969 +0100
+++ libetc-0.4.new/libetc.c    2010-02-24 22:59:42.719291086 +0100
@@ -78,14 +78,37 @@
 static int (*orig_mkstemp) (char *template);
 static int (*orig_mkstemp64) (char *template);
 
-static char *ETCDIR = ".config";
-static char *orig, *home, *etcdir;
+static char *CONFIGDIR = ".config";
+static char *DATADIR = ".local/share";
+static char *CACHEDIR = ".cache";
+static char *orig, *home, *etcdir, *data_files, *cache_files, *ignored_files;
 static int do_translate = 0;
 static int prefix_size = 0;
 
+// is the specified text in the list?
+static int am_i_in_list (const char *text, const char *list, int exact) {
+    char *token;
+
+    token = strtok(strdup(list), ":");
+    while (token != NULL) {
+        if(exact == 1 && strcmp(token, text) == 0) {
+      return 1;
+  } else if(exact == 0 && (strncmp(token, text, strlen(text)) == 0 || strncmp(token, text, strlen(token)) == 0)) {
+    PRINT_DEBUG("%s %s YES!\n", text, token);
+      return 1;
+  } else {
+    PRINT_DEBUG("%s %s NO!\n", text, token);
+  }
+
+  token = strtok(NULL, ":");
+    }
+
+    return 0;
+}
+
 // is the running exec blacklisted ?
 static int am_i_blacklisted () {
-    char running_exec[4096], *exec_blacklist, *str;
+    char running_exec[4096], *exec_blacklist;
     int len;
 
     if ((len = orig_readlink ("/proc/self/exe", running_exec, sizeof (running_exec) - 1))) {
@@ -93,16 +116,8 @@
         PRINT_DEBUG ("running exec: %s\n", running_exec);
         if ((exec_blacklist = getenv ("LIBETC_BLACKLIST"))) {
             PRINT_DEBUG ("blacklist: %s\n", exec_blacklist);
-            while ((str = strrchr (exec_blacklist, ':'))) {
-                if (0 == strcmp (++str, running_exec)) {
-                    PRINT_DEBUG ("I am blacklisted !\n");
-                    return 1;
-                }
-                str--;
-                str[0] = '\0';
-            }
-            if (0 == strcmp (exec_blacklist, running_exec)) {
-                PRINT_DEBUG ("I am blacklisted !\n");
+                              if (am_i_in_list (running_exec, exec_blacklist, 1)) {
+                                PRINT_DEBUG ("I am blacklisted !\n");
                 return 1;
             }
         }
@@ -111,22 +126,83 @@
     return 0;
 }
 
+// where does the file go?
+static int where_am_i (const char* filename) {
+    // 0 = config
+    // 1 = data
+    // 2 = cache
+    // 3 = ignore
+
+    int returntype = 0;
+
+    if (data_files && am_i_in_list (filename, data_files, 0)) {
+        returntype = 1;
+        PRINT_DEBUG ("I am data !\n");
+    } else if (cache_files && am_i_in_list (filename, cache_files, 0)) {
+        returntype = 2;
+        PRINT_DEBUG ("I am cache !\n");
+    } else if (ignored_files && am_i_in_list (filename, ignored_files, 0)) {
+        returntype = 3;
+        PRINT_DEBUG ("I am ignored !\n");
+    }
+
+
+    return returntype;
+}
+
 // find where to put the dotfiles
-static void find_etcdir () {
-    char *etc, *xdg_config_home;
+static void find_etcdir (int type, int initial) {
+    char *etc, *xdg_dir;
 
-    if (!(xdg_config_home = getenv ("XDG_CONFIG_HOME"))) {
-        if (!(etc = getenv ("ETC"))) {
-            etc = ETCDIR;
-            PRINT_DEBUG("default value: %s\n", etc);
-        }
-        PRINT_DEBUG("$ETC: %s\n", etc);
-        etcdir = malloc (strlen (home) + strlen (etc) + 1);
-        sprintf (etcdir, "%s/%s", home, etc);
-    } else {
-        PRINT_DEBUG("$XDG_CONFIG_HOME: %s\n", xdg_config_home);
-        etcdir = xdg_config_home;
-    }
+    if(type == 0) {
+        if (!(xdg_dir = getenv ("XDG_CONFIG_HOME"))) {
+            if (!(etc = getenv ("ETC"))) {
+                etc = CONFIGDIR;
+                PRINT_DEBUG("default value: %s\n", etc);
+            }
+            PRINT_DEBUG("$ETC: %s\n", etc);
+            etcdir = malloc (strlen (home) + strlen (etc) + 1);
+            sprintf (etcdir, "%s/%s", home, etc);
+        } else {
+            PRINT_DEBUG("$XDG_CONFIG_HOME: %s\n", xdg_dir);
+            etcdir = xdg_dir;
+        }
+        if(initial == 1){
+            CONFIGDIR = strdup(etcdir);
+        }
+    } else if(type == 1){
+        if (!(xdg_dir = getenv ("XDG_DATA_HOME"))) {
+            if (!(etc = getenv ("ETC"))) {
+                etc = DATADIR;
+                PRINT_DEBUG("default value: %s\n", etc);
+            }
+            PRINT_DEBUG("$ETC: %s\n", etc);
+            etcdir = malloc (strlen (home) + strlen (etc) + 1);
+            sprintf (etcdir, "%s/%s", home, etc);
+        } else {
+            PRINT_DEBUG("$XDG_DATA_HOME: %s\n", xdg_dir);
+            etcdir = xdg_dir;
+        }
+        if(initial == 1){
+            DATADIR = strdup(etcdir);
+        }
+    } else if(type == 2){
+        if (!(xdg_dir = getenv ("XDG_CACHE_HOME"))) {
+            if (!(etc = getenv ("ETC"))) {
+                etc = CACHEDIR;
+                PRINT_DEBUG("default value: %s\n", etc);
+            }
+            PRINT_DEBUG("$ETC: %s\n", etc);
+            etcdir = malloc (strlen (home) + strlen (etc) + 1);
+            sprintf (etcdir, "%s/%s", home, etc);
+        } else {
+            PRINT_DEBUG("$XDG_CACHE_HOME: %s\n", xdg_dir);
+            etcdir = xdg_dir;
+        }
+        if(initial == 1){
+            CACHEDIR = strdup(etcdir);
+        }
+    }
 }
 
 // mkdir etcdir if it does not exist
@@ -221,13 +297,25 @@
     orig = malloc (strlen (home) + 3);
     sprintf (orig, "%s/.", home);
 
-    find_etcdir ();
+            data_files = getenv ("LIBETC_DATA");
+            cache_files = getenv ("LIBETC_CACHE");
+            ignored_files = getenv ("LIBETC_IGNORE");
+            PRINT_DEBUG ("data files: %s\n", data_files);
+            PRINT_DEBUG ("cache files: %s\n", cache_files);
+            PRINT_DEBUG ("ignored files: %s\n", ignored_files);
+
+        find_etcdir (0, 1);
     mkdir_etcdir (etcdir);
 #ifdef XAUTH_HACK
     xauthority_hack (etcdir);
 #endif
 
-    PRINT_DEBUG("etcdir: %s\n", etcdir);
+        find_etcdir (1, 1);
+        mkdir_etcdir (etcdir);
+
+        find_etcdir (2, 1);
+        mkdir_etcdir (etcdir);
+
     prefix_size = strlen (etcdir);
     do_translate = 1;
 }
@@ -248,28 +336,43 @@
 
     wd = get_current_dir_name ();
 
-    if ((0 == strcmp (wd, home)) // if cwd == $HOME
-        && filename [0] == '.'   // and a dotfile
-        && (0 != strcmp (filename, "."))
-        && (0 != strncmp (filename, "./", 2))
-        && (0 != strncmp (filename, "..", 2))) {
-        char tmpfilename [strlen (home) + strlen (filename) + 2];
-        sprintf (tmpfilename, "%s/%s", home, filename);
-        if (0 != strncmp (tmpfilename, etcdir, strlen(etcdir))) { // do not translate if trying to read/write in $XDG_CONFIG_HOME
-            filename++; // remove the dot
+        if ((0 == strcmp (wd, home) && filename [0] == '.') || 0 == strncmp (filename, orig, strlen (orig))){
+            int filetype = where_am_i(filename);
+        
+            if(filetype != 3){
+                find_etcdir(filetype, 0);
+              
+            if ((0 == strcmp (wd, home)) // if cwd == $HOME
+                && filename [0] == '.'   // and a dotfile
+                && (0 != strcmp (filename, "."))
+                && (0 != strncmp (filename, "./", 2))
+                && (0 != strncmp (filename, "..", 2))) {
+              
+                char tmpfilename [strlen (home) + strlen (filename) + 2];
+                sprintf (tmpfilename, "%s/%s", home, filename);
+                if (0 == strncmp (tmpfilename, CONFIGDIR, strlen(CONFIGDIR))
+                || 0 == strncmp (tmpfilename, DATADIR, strlen(DATADIR))
+                || 0 == strncmp (tmpfilename, CACHEDIR, strlen(CACHEDIR))) { // do not translate if trying to read/write in $XDG_CONFIG/DATA/CACHE_HOME
+                              newfilename = strdup (filename);
+                } else {
+                    filename++; // remove the dot
             sprintf (newfilename, "%s/%s", etcdir, filename);
             *dest = newfilename;
             PRINT_DEBUG("RENAMED IN $HOME --> %s\n", newfilename);
         }
-    } else if (0 == strncmp (filename, orig, strlen (orig)) // if file name is $HOME/.something
-           && 0!= strncmp (filename, etcdir, strlen (etcdir)) ) { // do not translate if trying to read/write in $XDG_CONFIG_HOME
-        filename += strlen (home) + 2; // remove "$HOME/." from the filename
+            } else if (0 == strncmp (filename, orig, strlen (orig)) // if file name is $HOME/.something
+                   && (0!= strncmp (filename, CONFIGDIR, strlen (CONFIGDIR))
+                      && 0!= strncmp (filename, DATADIR, strlen (DATADIR))
+                      && 0!= strncmp (filename, CACHEDIR, strlen (CACHEDIR)))) { // do not translate if trying to read/write in $XDG_CONFIG/DATA/CACHE_HOME
+                filename += strlen (home) + 2; // remove "$HOME/." from the filename
         sprintf (newfilename, "%s/%s", etcdir, filename);
         *dest = newfilename;
         PRINT_DEBUG("RENAMED --> %s\n", newfilename);
+            }
     }
     
     free (wd);
+    }
 }
 
 #define REWRITE_FUNCTION_SIMPLE(return_type, function_name, signature, orig_call, error_return) \

It's not yet tested, though. I'll suggest it to the maintainer of the AUR libetc package tomorrow. Have fun with this if you want to, took me the better part of an afternoon.

Edit: Thanks, Barrucadu, for making something awesome even awesomer. wink

Last edited by Runiq (2010-02-24 22:16:09)

Offline

#48 2010-02-24 22:45:12

xelados
Member
Registered: 2007-06-02
Posts: 314
Website

Re: Put your $HOME in .home!

fsckd wrote:

By default? Hell no.

Why not? It'd clean some stuff up and migrating would be relatively painless.

Offline

#49 2010-02-25 13:55:11

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: Put your $HOME in .home!

fsckd wrote:

I don't bother with this. I let my home directory get trashed and keep my data files elsewhere (/n or whatever). Advantage: my data resides on a separate partition and is not bound to any one OS.

My own sentiments exactly! +1!
As far as _I_ am concerned, $HOME is part of the OS and as an ardent distrohopper and multibooter, my personal files are kept on a seperate partition - common to all distros.

Offline

#50 2010-02-28 03:25:02

tladuke
Member
Registered: 2009-07-23
Posts: 176

Re: Put your $HOME in .home!

ooh, wouldn't this make it easier to keep all the configs in git?

Offline

Board footer

Powered by FluxBB