Created
February 9, 2026 06:52
-
-
Save ZenBerry/c7fc8233361b7ca3cd55a53ce607b122 to your computer and use it in GitHub Desktop.
A MacOS terminal hook to show an active nvm node version dynamically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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