Skip to content

Instantly share code, notes, and snippets.

@ZenBerry
Created February 9, 2026 06:52
Show Gist options
  • Select an option

  • Save ZenBerry/c7fc8233361b7ca3cd55a53ce607b122 to your computer and use it in GitHub Desktop.

Select an option

Save ZenBerry/c7fc8233361b7ca3cd55a53ce607b122 to your computer and use it in GitHub Desktop.
A MacOS terminal hook to show an active nvm node version dynamically
# add it to ~/.zshrc
# then run: source ~/.zshrc
# expected result: (node v22.22.0) user@computer ~ %
# should change dynamically as you run nvm use *version*
autoload -U add-zsh-hook
setopt PROMPT_SUBST
node_prompt() {
if command -v node >/dev/null 2>&1; then
NODE_PROMPT="%F{cyan}(node $(node -v))%f "
else
NODE_PROMPT=""
fi
}
add-zsh-hook precmd node_prompt
PROMPT='${NODE_PROMPT}'"$PROMPT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment