Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XDG Base Directory Specification Compliance #250

Open
eddsalkield opened this issue Nov 25, 2019 · 9 comments
Open

XDG Base Directory Specification Compliance #250

eddsalkield opened this issue Nov 25, 2019 · 9 comments

Comments

@eddsalkield
Copy link
Contributor

Since 2010, the XDG Base Directory Specification has been widely accepted, defining a standard for the locations of user configuration files. Currently, rcm checks by default for the rcrc configuration file in ~/.rcrc, which is not in alignment with the specification.

I propose that the following behaviour be implemented, to locate the default .rcrc file:

  • The currently-default ~/.rcrc is checked. If it does not exist, then:
    • If $XDG_CONFIG_HOME is set, rcm checks $XDG_CONFIG_HOME/rcm/rcrc
    • If $XDG_CONFIG_HOME is not set, rcm checks $HOME/.config/rcm/rcrc

This would bring rcm into alignment with the specification, without breaking backwards compatibility.

@mat-m
Copy link
Contributor

mat-m commented Nov 30, 2019

If we follow XDG, then dotfiles folder should be somewhere in $XDG_DATA_HOME :

  • $XDG_DATA_HOME/rcm/dotfiles
    or at least
  • $XDG_DATA_HOME/dotfiles

Since XDG_DATA_HOME default value is $HOME/.local/share, it adds two folders to create before getting dotfiles. Does it mean we need a bootstrap option (discussion initialized in #103) to initialize this ?

@eddsalkield
Copy link
Contributor Author

eddsalkield commented Dec 7, 2019

There's a bit of a debate to be had as to where dotfiles should go in $XDG_CONFIG_HOME/rcm/dotfiles or $XDG_DATA_HOME/rcm/dotfiles. I think we can safely rule out $XDG_DATA_HOME/dotfiles, as people would not expect this location. The ambiguity being that the data to rcm in this instance are user configuration files. In my (maybe controversial) opinion, we should pick $XDG_CONFIG_HOME/rcm/dotfiles, since people would expect backing up their $XDG_CONFIG_HOME to back up all their dotfiles.

Either way, we do not need a bootstrap option to initalise this directory. As the specification (linked above) says:

If, when attempting to write a file, the destination directory is non-existant an attempt should be made to create it with permission 0700. If the destination directory exists already the permissions should not be changed. The application should be prepared to handle the case where the file could not be written, either because the directory was non-existant and could not be created, or for any other reason. In such case it may chose to present an error message to the user.

Then we just add behaviour to create dotfiles in the new location as opposed to the old.

Of course, following the specification to create files in these new locations does break backwards compatibility in at least a small way; people whose shell scripts depend on rcm initialising its files in the original directories would break. However, we would ensure that rcm continues to check the old locations, so that a standard user would notice no difference when updating to a compliant version.

@mat-m
Copy link
Contributor

mat-m commented Dec 11, 2019

Well, for rcm they are DATA and not CONFIG, that's why I used $XDG_DATA_HOME. And dotfiles folder will be amongst its own target, which is weird :)

Currently defaults are:

  • RC in ~/.rcrc
  • Files in ~/.dotfiles

XDG defaults would be:

  • RC in $XDG_CONFIG_HOME/rcm/rcrc ( ~/.config)
  • Files in $XDG_DATA_HOME/rcm/dotfiles (~/.local/share)

Maybe we can add a -x option to conform to XDG if no default is found (matching a RCXDG variable to set in your profile ?). An RCRC variable will always have the last word if set to avoid breaking compatibility.

@mike-burns
Copy link
Contributor

Let's make this work more seamlessly for XDG users.

The easiest lift is the original suggestion: look for ~/.rcrc and ${XDG_CONFIG_HOME:-~/.config}/.rcrc, in that order (did I get the XDG one right?). We can update rcrc(5) to document that this is the search path. I'd accept that pull request.

Once that is in place, an XDG-minded user can set DOTFILES_DIRS in their rcrc to $XDG_DATA_HOME/rcm/dotfiles. I'd enjoy documentation on how to XDG-ize one's rcm setup, maybe as part of rcm(7). That could be a fun documentation project if someone wants to take it on.

(In the meantime you can get far with the RCRC environment variable.)

@eddsalkield
Copy link
Contributor Author

I think this is almost right, although we really should incorporate @mat-m's approach of separating config files from data. The logical flow would be as follows:

The .rcrc file should be found by by:

  • Checking the location defined by $RCRC
  • Checking for ~/.rcrc
  • Checking ${XDG_CONFIG_HOME:-~/.config}/rcm/rcrc

The dotfiles directory should be found by:

  • Checking the location defined by $DOTFILES_DIRS
  • Checking for ~/.dotfiles
  • Checking ${XDG_DATA_HOME:-~/.local/share}/rcm/dotfiles

Using this resolution logic, new users will automatically use the XDG locations since the old default location checks will fail, and it would be backwards-compatible. No XDG-ising required!

@eddsalkield
Copy link
Contributor Author

I have a patch in the works for this - I'll submit it when I next have time to polish it up.

@ratijas
Copy link
Contributor

ratijas commented Nov 5, 2020

The easiest lift is the original suggestion: look for ~/.rcrc and ${XDG_CONFIG_HOME:-~/.config}/.rcrc, in that order (did I get the XDG one right?). We can update rcrc(5) to document that this is the search path. I'd accept that pull request.

I think it would be insane & confusing to have ~/.rcrc AND ${XDG_CONFIG_HOME:-~/.config}/.rcrc, so it should become a hard error. I mean, check both locations, and exit(1) when both files exist.

Generally, +1 for the XDG compliance.

@mike-burns
Copy link
Contributor

to have ~/.rcrc AND ${XDG_CONFIG_HOME:-~/.config}/.rcrc, so it should become a hard error.

OK yes, that seems correct. Thank you for catching that.

@UnkwUsr
Copy link

UnkwUsr commented Jan 8, 2022

I'm sorry for bump, but is there any progress? @eddsalkield

jonthn pushed a commit to jonthn/rcm that referenced this issue May 8, 2023
 This change the default of :

   - ~/.rcrc with ~/.dotfiles
   to
   - ~/.config/rcm/rcrc with ~/.local/share/rcm/dotfiles (XDG_xxxx)

 It's an _hard_ error to have both ~/.rcrc and ~/.config/rcm/rcrc,
 except for _compatibility_ to keep ~/.rcrc as a link to
 ~/.config/rcm/rcrc

 Completes thoughtbot#250
jonthn pushed a commit to jonthn/rcm that referenced this issue May 8, 2023
 This change the default of :

   - ~/.rcrc with ~/.dotfiles
   to
   - ~/.config/rcm/rcrc with ~/.local/share/rcm/dotfiles (XDG_xxxx)

 It's an _hard_ error to have both ~/.rcrc and ~/.config/rcm/rcrc,
 except for _compatibility_ to keep ~/.rcrc as a link to
 ~/.config/rcm/rcrc

 Completes thoughtbot#250
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants