Detached mode
Build a custom Zsh prompt from NBSP_DATA while nobsprompt handles non-spawning foreground collection, asynchronous refresh, and redraw.
Detached mode turns nbsp into a prompt-data backend for Zsh. It retains the
non-spawning foreground collector, asynchronous Git refresh, command timing,
job tracking, redraw requests, and external command editing. Your code owns
PROMPT and RPROMPT.
Initialize detached mode in ~/.zshrc:
eval "$(nbsp init zsh --detached --autosuggest)"
The first prompt mode initialized in a shell wins. node_version is derived
from the value of NVM_BIN at each collection, so it follows later NVM_BIN
changes as well as the value present during initialization. Omit
--autosuggest when another ghost-text plugin is already active.
Start from the real template
The shipped opinionated prompt is ordinary detached-style Zsh. Read the full commented file in Opinionated prompt and adapt it. The minimal example below is only a sketch; the opinionated file is the complete educational layout (quoting, git markers, duration, jobs, status).
eval "$(nbsp init zsh --detached --autosuggest)"
minimal_prompt() {
local path branch=
nbsp_prompt_quote "${NBSP_DATA[path]}"
path=$REPLY
if [[ ${NBSP_DATA[git_present]} == 1 && -n ${NBSP_DATA[git_branch]} ]]; then
nbsp_prompt_quote "${NBSP_DATA[git_branch]}"
branch=" [$REPLY]"
fi
PROMPT="${path}${branch} %# "
}
nbsp_data_update_functions+=(minimal_prompt)
minimal_prompt
The final call prepares a prompt before the first precmd data load. The
registered callback rebuilds it after every later successful, complete data
frame parse, including reloads requested when an asynchronous Git worker
finishes. A callback can therefore run even when the values did not change.
Ownership boundary
Detached mode does not inspect, splice, or restore your prompt strings.
Your prompt code owns:
- colors and glyphs;
- one-line, multiline, and right-side layout;
- segment visibility and duration thresholds;
PROMPT_SUBST;- terminal title and other OSC wrappers.
The backend owns:
- collecting prompt facts without starting Git or Node in the foreground;
- command timing and job count;
- asynchronous Git refresh;
- complete-frame
NBSP_DATAreplacement; - update callbacks and ZLE redraw requests;
- external command editing.