You are not logged in.
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
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
Ok I will delate backup's
Thanks
Shell Scripter | C/C++/Python/Java Coder | ZSH
Offline
Or you could try something like libetc
AWESOME.
Offline
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
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
Offline
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
^^
I imagine many people like me just leave show hidden files on.
Offline
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
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
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
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
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
bump -- anyone else experiencing the behavior I mentioned above?
Offline
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
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
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
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
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
Since this got bumped…
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?
Offline
How can you not be a ~ user????? It's so useful...
Offline
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
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
By default? Hell no.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline
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.
Last edited by Runiq (2010-02-24 22:16:09)
Offline
By default? Hell no.
Why not? It'd clean some stuff up and migrating would be relatively painless.
Offline
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
ooh, wouldn't this make it easier to keep all the configs in git?
Offline