ruby / debug

Debugging functionality for Ruby
BSD 2-Clause "Simplified" License
1.14k stars 127 forks source link

Respect XDG basedir spec #1031

Open jasonkarns opened 1 year ago

jasonkarns commented 1 year ago

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:

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

ko1 commented 1 year ago

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

On the https://github.com/vim/vim/issues/4275, it was closed because of duplication of https://github.com/vim/vim/issues/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 commented 1 year ago

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?

jgarber623 commented 1 year ago

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 commented 11 months ago

Thank you.

Next we need to define the search order.

jgarber623 commented 11 months ago

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 commented 11 months ago

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

jgarber623 commented 11 months ago

@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.