Skip to content

nb.plugin.zsh: default NBRC_PATH/NB_DIR/NB_HIST to XDG paths #85

Description

@ss-o

Problem

nb.plugin.zsh currently sets no defaults for the variables upstream nb
uses to decide where it writes files, so a fresh install falls back to
$HOME/.nbrc, $HOME/.nb, and (for nb shell) $HOME/.nb_history.

Upstream nb (vendored at src/nb) already honors these as
"${VAR:-default}", so exporting them before nb runs is enough — no
upstream patch needed.

Complication

Both of z-shell/nb's own documented Zi install recipes skip sourcing
nb.plugin.zsh entirely:

  • docs/README.md's primary recipe uses as'program'.
  • package.json's zi-ices.default uses as'completion'.

Zi does not source the plugin file under either as mode, so defaulting
logic placed only in nb.plugin.zsh's body is effectively dead code for
users following the README. The fix needs an atinit hook (which Zi runs
regardless of as) added to both the README recipes and
package.json's zi-ices.default, in addition to the same guarded logic
inside nb.plugin.zsh for anyone who does source it directly (Oh My Zsh,
manual source, or a non-as'program' ice).

Proposed defaults

Variable New default Skip if this legacy path already exists
NBRC_PATH ${XDG_CONFIG_HOME:-$HOME/.config}/nb/nbrc ~/.nbrc
NB_DIR ${XDG_DATA_HOME:-$HOME/.local/share}/nb ~/.nb
NB_HIST ${XDG_STATE_HOME:-$HOME/.local/state}/nb/history ~/.nb_history

Each default only applies when the variable is unset and its legacy
$HOME path doesn't already exist, so existing installs keep working
unchanged and only fresh installs get XDG paths. All other nb variables
need no plugin change since nb already reads them the same way.

NBRC_PATH's parent directory needs an explicit mkdir -p when we default
it to the nested .../nb/nbrc path, because upstream _init_create_rc_file
(nb init) writes the rc file with a bare > redirect and no mkdir -p
safety net, unlike its data-dir creation path.

Out of scope (tracked separately)

nb.plugin.zsh's current entry-point boilerplate uses the shared Plugins
hash key pattern that PATTERNS.md and the current Zsh Plugin Standard both
say not to use (unconditional overwrite with no pre-load snapshot, no
unload function). That's a distinct, more mechanical fix and will get its
own issue rather than being bundled into this one.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions