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

Respect XDG basedir spec #1031

Open
jasonkarns opened this issue Oct 30, 2023 · 7 comments
Open

Respect XDG basedir spec #1031

jasonkarns opened this issue Oct 30, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@jasonkarns
Copy link

Your proposal
I propose that debug respect the XDG Base Directory Specification such that files are written to locations controlled by user environment variables.

There are at least three relevant files:

  • rdbg_history
  • rdbgrc
  • unix_domain_socket_dir

Presently, the history file may be forced into a different location with the RUBY_DEBUG_HISTORY_FILE env var. While helpful, this does not adhere to the desire for single-configuration (setting XDG_* vars once and not needing to configure each of hundreds of different utilities). It should default to a file or directory in XDG_STATE_HOME (which itself defaults to $HOME/.local/state)

The unix_domain_socket_dir is already very nearly adhering to Xdg, as its first implicit location (after checking explicit config setting) uses XDG_RUNTIME_DIR.

The rdbgrc (and .rb variant) have no env var equivalents and so cannot even be set explicitly. However, they should be using files within XDG_CONFIG_HOME (which defaults to $HOME/.config). Perhaps $XDG_CONFIG_HOME/rdbg/config or $XDG_CONFIG_HOME/rdbg/config.rb ?

Additional context
The Xdg basedir spec is here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Rationale

  • keeps user's homedirectory clean
  • allows versioning of configuration files cleanly (ie, dotfiles repo to version-control .config but not cache or data files that also typically end up in homedir)
  • allows single-configuration changes to move configuration to different directory tree (for testing, for simulated environments, and many other unknowable use-cases)
@ko1
Copy link
Collaborator

ko1 commented Nov 14, 2023

We need to make migration plan.
~/.rdbgrc (and so on) are already there so we need to respect current files.

On the vim/vim#4275, it was closed because of duplication of vim/vim#2034 which has huge comments and not accepted (I can't read all of comments) but #4275 proposes:

~/.vimrc
~/.vim/vimrc
$XDG_CONFIG_DIR/vim/vimrc (if the env var is unset, its default is ~/.config)

For rdbgrc, making searching order as

~/.rdbgrc
$XDG_RUNTIME_DIR/rdbg/config if `XDG_RUNTIME_DIR` is available

is one idea.

For ~/.rdbg_histroy there are two options:

  1. search ~/.rdbg_history and $XDG_STATE_HOME/rdbg/history if $XDG_STATE_HOME is available
  2. use $XDG_STATE_HOME/rdbg/history and ignore existing ~/.rdbg_history if $XDG_STATE_HOME is available
    2.1. with warning

Could you survey another software migration plan?

BTW my Ubuntu 24.04 machines only have the following XDG envvals:

XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
XDG_RUNTIME_DIR=/run/user/1000

Who set config dir and state dir?

@ko1
Copy link
Collaborator

ko1 commented Nov 14, 2023

BTW (2) I found NVIM_APPNAME to change the app name (and we can switch configurations at once). Should we support it with RUBY_DEBUG_APPNAME or something similar?

@ko1 ko1 added the enhancement New feature or request label Nov 14, 2023
@jgarber623
Copy link

Some thoughts on this issue based on @ko1's comments above:

For rdbgrc, making searching order as

~/.rdbgrc
$XDG_RUNTIME_DIR/rdbg/config if `XDG_RUNTIME_DIR` is available

is one idea.

I'd expect to create a config file in $XDG_CONFIG_HOME (e.g. ~/.config) at a path like $XDG_CONFIG_HOME/rdbg/config. I believe that more closely follows patterns details on the XDG page on the Arch wiki.

For ~/.rdbg_histroy there are two options:

  1. search ~/.rdbg_history and $XDG_STATE_HOME/rdbg/history if $XDG_STATE_HOME is available
  2. use $XDG_STATE_HOME/rdbg/history and ignore existing ~/.rdbg_history if $XDG_STATE_HOME is available
    2.1. with warning

I think $XDG_DATA_HOME (e.g. ~/.local/share) is the more appropriate place for history files. Similar to my note above, the XDG page on the Arch wiki cites a number of examples using $XDG_DATA_HOME for history files.

@ko1
Copy link
Collaborator

ko1 commented Dec 5, 2023

Thank you.

Next we need to define the search order.

@ko1 ko1 modified the milestone: v1.9.0 Dec 5, 2023
@jgarber623
Copy link

I took a quick glance at the entries in sections 2.2 and 2.3 on the Arch wiki and, where noted, it looks like most apps prefer the "legacy" file (e.g. ~/.rdbg_history) if present. Otherwise, search for the $XDG_*-prefixed file path.

So, a restated version of @ko1's proposal above:

  1. prefer ~/.rdbgrc if present,
  2. else, $XDG_CONFIG_HOME/rdbg/config if $XDG_CONFIG_HOME is set and $XDG_CONFIG_HOME/rdbg/config is present,
  3. else, no customized user configuration

For the history file:

  1. prefer ~/.rdbg_history if present,
  2. else, $XDG_DATA_HOME/rdbg/history if $XDG_DATA_HOME is set¹

¹ There'd need to be a check for this file path. If it exists, great! If not, create the path $XDG_DATA_HOME/rdbg and touch $XDG_DATA_HOME/rdbg/history.

@ko1
Copy link
Collaborator

ko1 commented Dec 27, 2023

Thank you. I'll make it (or PR is welecome)

jgarber623 added a commit to jgarber623/debug that referenced this issue Dec 31, 2023
This commit implements XDG directory support for this gem's history file
in accordance with the rules outlined in ruby#1031:

> For the history file:
>
> 1. prefer `~/.rdbg_history` if present,
> 2. else, `$XDG_DATA_HOME/rdbg/history` if `$XDG_DATA_HOME` is set¹
>
> ¹ There'd need to be a check for this file path. If it exists, great!
> If not, create the path `$XDG_DATA_HOME/rdbg` and touch
> `$XDG_DATA_HOME/rdbg/history`.

See: ruby#1031 (comment)
jgarber623 added a commit to jgarber623/debug that referenced this issue Dec 31, 2023
This commit implements XDG directory support for this gem's `.rdbgrc`
configuration file in accordance with the rules outlined in ruby#1031:

> 1. prefer `~/.rdbgrc` if present,
> 2. else, `$XDG_CONFIG_HOME/rdbg/config` if `$XDG_CONFIG_HOME` is set
> and `$XDG_CONFIG_HOME/rdbg/config` is present,
> 3. else, no customized user configuration

See: ruby#1031 (comment)
@jgarber623
Copy link

@ko1 I just opened a draft PR for this: #1055.

I think I got the desired logic correct, though I'm open to feedback and could use some help with adding any tests that the core team may wish to see.

jgarber623 added a commit to jgarber623/debug that referenced this issue Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

3 participants