From 44166c5ae8fed66abcd74ff0ab6996958c01c6ef Mon Sep 17 00:00:00 2001 From: Corey Woodworth Date: Mon, 5 May 2025 10:59:49 -0400 Subject: [PATCH 1/6] Use XDG_CONFIG_HOME if available --- nb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nb b/nb index 9d343bfca..1063e6b45 100755 --- a/nb +++ b/nb @@ -440,8 +440,15 @@ _option_value_is_present() { # # Default: `$HOME/.nbrc` # -# The location of the .nbrc configuration file. -export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}" +# Check if XDG_CONFIG_HOME exists +if [[ -n "${XDG_CONFIG_HOME}" ]]; then + # If XDG_CONFIG_HOME exists put .nbrc config file in a subdirectory. + mkdir -p "${XDG_CONFIG_HOME}/${_ME}" && + export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME}/.${_ME}rc"}" +else + # Otherwise, use the default path + export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}" +fi # Handle symlinked NBRC_PATH. if [[ -L "${NBRC_PATH}" ]] From e29aa7b6b8d82dae0db68f034ec99aac792f76ca Mon Sep 17 00:00:00 2001 From: Corey Woodworth Date: Wed, 7 May 2025 10:53:46 -0400 Subject: [PATCH 2/6] discard file extension when creating directory --- nb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nb b/nb index 1063e6b45..e3e803bb5 100755 --- a/nb +++ b/nb @@ -443,8 +443,8 @@ _option_value_is_present() { # Check if XDG_CONFIG_HOME exists if [[ -n "${XDG_CONFIG_HOME}" ]]; then # If XDG_CONFIG_HOME exists put .nbrc config file in a subdirectory. - mkdir -p "${XDG_CONFIG_HOME}/${_ME}" && - export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME}/.${_ME}rc"}" + mkdir -p "${XDG_CONFIG_HOME}/${_ME%.*}" && + export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME%.*}/.${_ME}rc"}" else # Otherwise, use the default path export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}" From 386a30cbb724c8ff9fa72de834fb695454975cad Mon Sep 17 00:00:00 2001 From: Corey Woodworth Date: Wed, 7 May 2025 11:08:37 -0400 Subject: [PATCH 3/6] handle cases with multiple extensions --- nb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nb b/nb index e3e803bb5..f8bb3e837 100755 --- a/nb +++ b/nb @@ -443,8 +443,8 @@ _option_value_is_present() { # Check if XDG_CONFIG_HOME exists if [[ -n "${XDG_CONFIG_HOME}" ]]; then # If XDG_CONFIG_HOME exists put .nbrc config file in a subdirectory. - mkdir -p "${XDG_CONFIG_HOME}/${_ME%.*}" && - export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME%.*}/.${_ME}rc"}" + mkdir -p "${XDG_CONFIG_HOME}/${_ME%%.*}" && + export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME%%.*}/.${_ME}rc"}" else # Otherwise, use the default path export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}" From 79b4b8cf432e8182ee76b48e6c37c4d7191addcb Mon Sep 17 00:00:00 2001 From: MrDowntempo Date: Fri, 13 Jun 2025 14:20:35 +0000 Subject: [PATCH 4/6] Update nb docs to mention new defaults Co-authored-by: Zachery Crandall --- nb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nb b/nb index f8bb3e837..35e4fb9ca 100755 --- a/nb +++ b/nb @@ -438,7 +438,8 @@ _option_value_is_present() { # $NBRC_PATH # -# Default: `$HOME/.nbrc` +# Default: `$HOME/.nbrc`, or `$XDG_CONFIG_HOME/nb/config` if `XDG_CONFIG_HOME` +# is defined and `$HOME/.nbrc` does not already exist # # Check if XDG_CONFIG_HOME exists if [[ -n "${XDG_CONFIG_HOME}" ]]; then From 9686f24f6c483b964c12eba8165111bab6d9de97 Mon Sep 17 00:00:00 2001 From: MrDowntempo Date: Fri, 13 Jun 2025 14:21:24 +0000 Subject: [PATCH 5/6] Make nbrc in XDG_CONFIG_HOME not a dotfile by default Co-authored-by: Zachery Crandall --- nb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nb b/nb index 35e4fb9ca..5ac0a1351 100755 --- a/nb +++ b/nb @@ -445,7 +445,7 @@ _option_value_is_present() { if [[ -n "${XDG_CONFIG_HOME}" ]]; then # If XDG_CONFIG_HOME exists put .nbrc config file in a subdirectory. mkdir -p "${XDG_CONFIG_HOME}/${_ME%%.*}" && - export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME%%.*}/.${_ME}rc"}" + export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME%%.*}/${_ME}rc"}" else # Otherwise, use the default path export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}" From e22285b0dcde42fd6b11033c54a8232c8323550e Mon Sep 17 00:00:00 2001 From: MrDowntempo Date: Mon, 30 Jun 2025 03:35:06 +0000 Subject: [PATCH 6/6] Update nb Co-authored-by: Zachery Crandall --- nb | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/nb b/nb index 5ac0a1351..b507e0393 100755 --- a/nb +++ b/nb @@ -440,17 +440,29 @@ _option_value_is_present() { # # Default: `$HOME/.nbrc`, or `$XDG_CONFIG_HOME/nb/config` if `XDG_CONFIG_HOME` # is defined and `$HOME/.nbrc` does not already exist -# -# Check if XDG_CONFIG_HOME exists -if [[ -n "${XDG_CONFIG_HOME}" ]]; then - # If XDG_CONFIG_HOME exists put .nbrc config file in a subdirectory. - mkdir -p "${XDG_CONFIG_HOME}/${_ME%%.*}" && - export NBRC_PATH="${NBRC_PATH:-"${XDG_CONFIG_HOME}/${_ME%%.*}/${_ME}rc"}" + +# This is the old way of determining the global nbrc path, to preserve +# backwards compatibility. I propose deprecating it. +_deprec_default_nbrc="${HOME}/.${_ME}rc" + +# This is the new, XDG-compliant default location +_xdg_default_nbrc="${XDG_CONFIG_HOME:-${HOME}/.config}/${_ME%%.*}/${_ME}rc" + +# Choose a default path to use +if [[ -e "${_deprec_default_nbrc}" ]]; then + # If the old default nbrc file exists, use it + _nbrc_path="${_deprec_default_nbrc}" + # TODO: Potentially output a warning here that this location is deprecated. else - # Otherwise, use the default path - export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}" + # Otherwise, use the new, XDG-compliant default path + _nbrc_path="${_xdg_default_nbrc}" fi +# In either case, defer to a potential external definition of NBRC_PATH +export NBRC_PATH="${NBRC_PATH:-${_nbrc_path}}" +# TODO: Create the path to the nbrc file if it does not exist yet. Perhaps do +# this in the _init_create_rc_file function. + # Handle symlinked NBRC_PATH. if [[ -L "${NBRC_PATH}" ]] then