From 7184490f549b5d0a55b26234cfe2efff08dd635f Mon Sep 17 00:00:00 2001 From: MestreLion Date: Fri, 13 May 2022 13:33:06 -0300 Subject: [PATCH] * usr/lib/byobu/include/dirs.in: #LP:1973362 - improve BYOBU_CONFIG_DIR / XDG handling, simplifying logic and not requiring user to both create the dir and set an env var. Change logic to: BYOBU_CONFIG_DIR if set, ~/.byobu if exists, else XDG_CONFIG_DIR(~/.config)/byobu. Always create the dir if needed. --- usr/lib/byobu/include/dirs.in | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/usr/lib/byobu/include/dirs.in b/usr/lib/byobu/include/dirs.in index 8aaaaf3f..13abf3a3 100755 --- a/usr/lib/byobu/include/dirs.in +++ b/usr/lib/byobu/include/dirs.in @@ -25,22 +25,19 @@ PKG="byobu" [ -n "$BYOBU_PREFIX" ] || BYOBU_PREFIX="@prefix@" # Create and export the user configuration directory -if [ -d "$BYOBU_CONFIG_DIR" ]; then - export BYOBU_CONFIG_DIR="$BYOBU_CONFIG_DIR" -elif [ -d "$XDG_CONFIG_HOME" ]; then - # Use XDG, as some users insist on such nonsense :-) - export BYOBU_CONFIG_DIR="$XDG_CONFIG_HOME/$PKG" -elif [ -d "$HOME/.config/$PKG" ]; then - # Use XDG config directory, if it exists - export BYOBU_CONFIG_DIR="$HOME/.config/$PKG" -elif [ -d "$HOME/.local/share/$PKG" ]; then - # Use XDG local directory, if it exists - export BYOBU_CONFIG_DIR="$HOME/.local/share/$PKG" -else - # And to default to good old classic config dir location! - export BYOBU_CONFIG_DIR="$HOME/.$PKG" +# BYOBU_CONFIG_DIR if set, ~/.byobu if it exists, otherwise XDG_CONFIG_HOME/byobu +if [ -z "$BYOBU_CONFIG_DIR" ]; then + if [ -d "$HOME/.$PKG" ]; then + export BYOBU_CONFIG_DIR="$HOME/.$PKG" + else + _xdg="${XDG_CONFIG_HOME:-"$HOME"/.config}" + # Spec says XDG_CONFIG_HOME must not be world-readable + [ -d "$_xdg" ] || mkdir -p -m 700 "$_xdg" + export BYOBU_CONFIG_DIR="$_xdg/$PKG" + unset _xdg + fi fi -[ -d "$BYOBU_CONFIG_DIR" ] || mkdir -p "$BYOBU_CONFIG_DIR/bin" +[ -d "$BYOBU_CONFIG_DIR/bin" ] || mkdir -p "$BYOBU_CONFIG_DIR/bin" # Grab the global, then local socket directory [ -r "/etc/$PKG/socketdir" ] && . "/etc/$PKG/socketdir"