Improve BYOBU_CONFIG_DIR / XDG handling

Bug #1973362 reported by MestreLion
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
byobu
Fix Committed
Undecided
Unassigned

Bug Description

I'm fully aware that handling BYOBU_CONFIG_DIR, and by an extent XDG_CONFIG_HOME, has always been painful, there are several bug reports, patches and commits about it, specially in 2010-2013.

That said, I believe there's room for improvement, to both increase conformity to XDG *and* simplify the handling logic.

Currently, byobu first checks for the existence of several dirs and then sets its env var and then creates the dir. It also does so in a way the user must BOTH create the dir AND set the corresponding env var.

However, software traditionally first checks if one or more env vars are set, in order of precedence and with a given default, and then creates the dir if necessary.

So I propose the following logic:
- if BYOBU_CONFIG_DIR is set, use it
- for backward-compability, if ~/.byobu exists, use it
- otherwise, use ${XDG_CONFIG_DIR:-$HOME/.config}/byobu
- In all cases, create the dir if it does not exist

That's way simpler and better, for both byobu and users (XDG or not).

Speaking of XDG: Currently there are 3 checks for XDG-related dirs. No need, just choose either XDG_CONFIG_HOME or XDG_DATA_HOME and use it as default. The current contents of ~/.byobu qualify it to either one.

So, if using XDG_DATA_HOME, the relevant code would be:

https://bazaar.launchpad.net/~kirkland/byobu/trunk/view/head:/usr/lib/byobu/include/dirs.in

# Create and export the user configuration directory
# ~/.byobu if it exists, otherwise XDG_DATA_HOME(~/.local/share)/byobu
if [ -z "$BYOBU_CONFIG_DIR" ]; then
 if [ -d "$HOME/.$PKG" ]; then
  export BYOBU_CONFIG_DIR="$HOME/.$PKG"
 else
  export BYOBU_CONFIG_DIR="${XDG_DATA_HOME:-"$HOME"/.local/share}/$PKG"
 fi
fi
[ -d "$BYOBU_CONFIG_DIR/bin" ] || mkdir -p "$BYOBU_CONFIG_DIR/bin"

That's _half_ the current handling code.

I'm also attaching a patch for XDG_CONFIG_DIR, as it has an additional step.
I can also provide a patch for the corresponding documentation (man pages, etc)

Revision history for this message
MestreLion (mestrelion) wrote :
Revision history for this message
MestreLion (mestrelion) wrote :

TL;DR:
- Don't require user to both create the dir and set an env var.
- Use BYOBU_CONFIG_DIR if set, ~/.byobu if exists, otherwise XDG_CONFIG_DIR(~/.config)/byobu
- Always create the dir if needed.

Revision history for this message
MestreLion (mestrelion) wrote :
Changed in byobu:
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.