Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,18 @@ _option_value_is_present() {

# $NBRC_PATH
#
# Default: `$HOME/.nbrc`
#
# The location of the .nbrc configuration file.
export NBRC_PATH="${NBRC_PATH:-"${HOME}/.${_ME}rc"}"
# 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I think this would always use XDG_CONFIG_HOME/nb/.nbrc if XDG_CONFIG_HOME is defined. It should probably still default to using $HOME/.nbrc if the file already exists so it doesn't break existing installations and setups.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I think you're right. I hadn't considered that.

# If XDG_CONFIG_HOME exists put .nbrc config file in a subdirectory.
mkdir -p "${XDG_CONFIG_HOME}/${_ME%%.*}" &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an _init_create_rc_file function defined here already. Should creation of the config directory be part of that function instead? I think it would just require one line before writing the default nbrc file, something like this:

mkdir -p "$(dirname ${NBRC_PATH})"

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"}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option for the default config location is $HOME/.config/nb/ (the default value recommended in the XDG spec for XDG_CONFIG_HOME). Any thoughts from the maintainers/other users?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if it made sense to conform to the spec, if XDG_CONFIG_HOME wasn't explicitly set, especially since you can have independent notebooks in folders withe their own .nbrc and that wasn't the current default. But I would prefer if nb followed the spec by default (Hence the patch)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't aware that each notebook could have its own .nbrc file! I'm struggling to find where this mentioned in the user guide website (https://xwmx.github.io/nb/), but I think I see the behavior defined starting on L564. Do you know if this behavior is documented in the user guide website yet?

Regardless, as far as I can tell the default for NBRC_PATH does not affect sourcing notebook-specific .nbrc files. The notebook-specific settings are hard-coded to be named .nbrc and NB_NOTEBOOK_PATH seems to depend on NB_DIR but not NBRC_PATH. NBRC_PATH is sourced on L455 prior to $NB_NOTEBOOK_PATH/.nbrc on L567, so I think regardless of default location they will both be sourced.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zachcran It's currently undocumented. If I recall correctly, the original use case where this came up was about using a specific editor for a notebook, which made me think about it as being more for user-specific settings, and therefore something that shouldn't be checked into the notebook repo. However, this would have to be .gitignored manually, so it seemed complicated and I decided to figure it out later. I'm open to suggestions.

Copy link
Owner

@xwmx xwmx Jun 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, that is correct that the notebook .nbrc should be unaffected by $NBRC_PATH. The settings in notebook .nbrc files should override any matching global settings regardless of where they are set.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry for possible duplicate notifications, GitHub was behaving a bit strangely there) Thanks for the explanation! Is the ability to have notebook-specific .nbrc files something that you would like documented if someone is willing to do it? I could make an issue about it and label it with something like "Help Wanted" for now if you would like (and maybe work on it in the future, no promises though).

therefore something that shouldn't be checked into the notebook repo. However, this would have to be .gitignored manually, so it seemed complicated and I decided to figure it out later. I'm open to suggestions.

Would excluding the .nbrc file during the git add call be sufficient? After some digging, I learned that you can use "exclude" pathspecs with git add --all to ignore certain files. This would just require changing git -C "${_notebook_path}" add --all on L3768 to git -C "${_notebook_path}" add --all ':!.nbrc'. We can create a separate issue to discuss this further if needed, since it is a bit off topic here.

fi

# Handle symlinked NBRC_PATH.
if [[ -L "${NBRC_PATH}" ]]
Expand Down