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

Add support for XDG Base Directory Specification #69

Closed
mdebusk opened this issue Jul 25, 2020 · 10 comments
Closed

Add support for XDG Base Directory Specification #69

mdebusk opened this issue Jul 25, 2020 · 10 comments
Milestone

Comments

@mdebusk
Copy link

mdebusk commented Jul 25, 2020

Boxes currently looks in $HOME for its user configuration file. This practice clutters $HOME with countless dotfiles and makes organization difficult. The XDG Base Directory Specification helps to solve this problem by putting a program-specific directory under (usually) $HOME/.config. I would love to see boxes support this.

I am currently running boxes version 1.2 on Ubuntu 18.04.4 LTS.

@tsjensen
Copy link
Member

Thanks for sharing this idea! It seems to me to be a more generalized version of #5.

The XDG Spec has some weird requirements, such as having to detect when a user logs on, and creating a directory at that time. We would probably not be able to to that. But we could at least know about the environment variables and look for config files in the right places.

I think in addition to precedence etc. it is necessary to be able to read more than 1 config file. In that way, we could have the config that is shipped with boxes, and user-specific files which add to that.

@mdebusk
Copy link
Author

mdebusk commented Jul 26, 2020

Thanks for sharing this idea! It seems to me to be a more generalized version of #5.

I must have misunderstood #5. I thought it was asking to be able to choose which config file to use, e.g., specifying it on the command line.

we could at least know about the environment variables and look for config files in the right places.

That's all I was really asking for.

I think in addition to precedence etc. it is necessary to be able to read more than 1 config file. In that way, we could have the config that is shipped with boxes, and user-specific files which add to that.

Yes. I was thinking I might want to edit a couple of the styles to include vim's folding markers. That's not something most people would want, I believe, but it'd save me a couple of minutes a year. :D

@tsjensen
Copy link
Member

I must have misunderstood #5. I thought it was asking to be able to choose which config file to use, e.g., specifying it on the command line.

Well, never mind! (We have the -f option already.)

I'll keep both issues open until we have this sorted out. Please feel free to contribute! These days, boxes evolves mainly through contributions.

@mdebusk
Copy link
Author

mdebusk commented Jul 27, 2020

Please feel free to contribute! These days, boxes evolves mainly through contributions.

If I were at all competent with programming, I would. This looks like a fun project.

@tsjensen
Copy link
Member

tsjensen commented Feb 20, 2021

I'm actually looking at this feature request again. XDG ist somewhat overengineered and not very precise, it seems, and there is discussion on the best degree to which to implement it. But it also seems to me that we should implement at least some of it.

My current take is this:

Precedence Path Source Type Comment
1 cmd line -f boxes legacy file(!) or dir should be a file, but could now also be a dir
2 $BOXES boxes legacy file(!) or dir should be a file, but could now also be a dir
3 $HOME boxes legacy dir  
4 $XDG_CONFIG_HOME/boxes XDG dir  
5 $HOME/.config/boxes XDG dir  
6 /etc/xdg/boxes XDG dir  
7 the hard-coded system-wide config file mentioned in man page boxes legacy file  
8 /usr/local/share/boxes XDG dir if it were a file, then only as per (7)
9 /usr/share/boxes XDG dir if it were a file, then only as per (7)

The XDG environment variable $XDG_CONFIG_DIRS would not be supported. However, its default value would be supported as (8) and (9) above.

Whenever the type is dir in the table above, in that directory we'll look for these files, in this order:

  1. .boxes
  2. box-designs
  3. boxes-config
  4. boxes

As soon as the first valid file is found, we use that and stop the search.

What do you think? Would this be sufficient?

@mdebusk
Copy link
Author

mdebusk commented Feb 20, 2021

I think this would be excellent.

@tsjensen
Copy link
Member

tsjensen commented Feb 21, 2021

Ok, I am using this comment to document the new behavior until it is done. So this comment may change a few times.

Prec. Path Source Type Comment
1 cmd line -f boxes legacy file(!) or dir should be a file, but could now also be a dir; must be present if specified
2 $BOXES boxes legacy file(!) or dir should be a file, but could now also be a dir; must be present if set
3 $HOME boxes legacy dir   
4 $XDG_CONFIG_HOME/boxes XDG dir   
5 $HOME/.config/boxes XDG dir   
6 Linux/Unix: the hard-coded system-wide config file mentioned in man page
Windows: .cfg file located next to .exe file with the same base name, default to C:\boxes.cfg
boxes legacy file  
7 /etc/xdg/boxes XDG dir likely not present on Win
8 /usr/local/share/boxes XDG dir if it were a file, then only as per (6); likely not present on Win
9 /usr/share/boxes XDG dir if it were a file, then only as per (6); likely not present on Win

The XDG environment variable $XDG_CONFIG_DIRS will not be supported. However, its default value would be supported as (8) and (9) above. In general, XDG will be supported on Windows, but in practice, this will probably only be useful for $HOME/.config, because the global directories are unlikely to exist.

Whenever the type is dir in the table above, in that directory we'll look for these files, in this order:

Linux/Unix Windows
  1. .boxes (boxes legacy)
  2. box-designs (new behavior)
  3. boxes-config (boxes legacy)
  4. boxes (boxes legacy)
  1. boxes.cfg (boxes legacy)
  2. box-designs.cfg (new behavior)
  3. boxes-config (boxes legacy)

As soon as the first valid file is found, we use that and stop the search.

tsjensen added a commit that referenced this issue Feb 22, 2021
for config file discovery. Also, the config file is searched in
more places, and can have more names. Details in issue comments.
tsjensen added a commit that referenced this issue Feb 23, 2021
for config file discovery. Also, the config file is searched in
more places, and can have more names. Details in issue comments.
tsjensen added a commit that referenced this issue Feb 24, 2021
for config file discovery. Also, the config file is searched in
more places, and can have more names. Details in issue comments.
tsjensen added a commit that referenced this issue Feb 24, 2021
This means we have some XDG support on Windows, too,
although some global locations like /etc/xdg are unlikely to exist.
tsjensen added a commit that referenced this issue Feb 26, 2021
for config file discovery. Also, the config file is searched in
more places, and can have more names. Details in issue comments.
tsjensen added a commit that referenced this issue Feb 26, 2021
This means we have some XDG support on Windows, too,
although some global locations like /etc/xdg are unlikely to exist.
@tsjensen tsjensen added this to the v2.1.0 milestone Feb 26, 2021
@tsjensen
Copy link
Member

Done. This will be in the v2.1.0 release.

tsjensen added a commit that referenced this issue Mar 14, 2021
for config file discovery. Also, the config file is searched in
more places, and can have more names. Details in issue comments.
tsjensen added a commit that referenced this issue Mar 14, 2021
This means we have some XDG support on Windows, too,
although some global locations like /etc/xdg are unlikely to exist.
tsjensen added a commit that referenced this issue Mar 19, 2021
for config file discovery. Also, the config file is searched in
more places, and can have more names. Details in issue comments.
tsjensen added a commit that referenced this issue Mar 19, 2021
This means we have some XDG support on Windows, too,
although some global locations like /etc/xdg are unlikely to exist.
@tsjensen
Copy link
Member

By the way, code for the already completed new features is collected on the rc_2.1.0 branch, in case you want to have a look.

@mdebusk
Copy link
Author

mdebusk commented Mar 20, 2021 via email

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

2 participants