tmux-plugins/tmux-sidebar

Support XDG Base Directory Specification for `SIDEBAR_DIR`

Closed this issue · 1 comments

erikw commented

Tmux support putting the config in the XDG path $XDG_CONFIG_PATH/tmux/tmux.conf and I noticed that this plugin will still create a file $HOME/.tmux/sidebar/directory_widths.txt, thus polluting $HOME.

Background

Lately the XDG Base Directory Specification has been gaining quite a steady popularity, even though it's been around for a long time already. The basic idea is to standardize where programs put their files e.g. all config files in a certain directory. The benefits for end users are many, including:

  • No polluted $HOME/
  • Can easily grep for only config files in $XDG_CONFIG_HOME
  • Can decide where to store configurations in more complex setups (multi system setup e.g.)
  • Easily wipe state by removing $XDG_STATE_HOME or even $XDG_DATA_HOME, but without destroying and configuration files.

The first point is maybe what most end users enjoy the most though.

How

Specifically for this project, this should mean that the search for the configuration file should be done like:

  1. if $XDG_CONFIG_HOME is set, look for $XDG_CONFIG_HOME/tmux/sidebar/directory_widths.txt
  2. elseif $XDG_CONFIG_HOME is unset, use the default value for the envvar which is $HOME/.config. Thus, the config file to look for is at $HOME/.config/tmux/sidebar/directory_widths.txt
  3. else fall-back to current legacy $HOME/.tmux/sidebar/directory_widths.txt

The first two steps to can be codifed in bash like:
${XDG_CONFIG_HOME:-$HOME/.config}/amethyst/amethyst.yml

I noticed that variables.sh set base dir path as an envvar $SIDEBAR_DIR:

SIDEBAR_DIR="$HOME/.tmux/sidebar"

Maybe it's possible to override this value as a workaround until full XDG support is added? 🤔

I'd accept a PR for this