powerlevel10k
powerlevel10k copied to clipboard
Support fnm for switching/displaying node version
Hi,
Thanks for this fantastic theme :)
It would be nice to support fnm in addition to nvm, nodenv and nodeenv.
Fast and simple Node.js version manager, built in native ReasonML https://github.com/Schniz/fnm
Hi. While we're on the same topic, I would like to request for n too
Node.js version management: no subshells, no profile setup, no convoluted API, just simple. https://github.com/tj/n
@kuntau Please file a separate issue.
@djhi and @kuntau, you might try to enable the node_version prompt element. I used this with fnm and am now using it with nvs. Both work fine, and it should work for n, too.
node_version shows the output of node --version. For comparison, nvm and all the *env segments show which version you would have if you enabled the current environment. If in your setup the environment is enabled on cd, then these are equivalent.
I recently switched to fnm and wrote this custom segment that does something close enough to what prompt_nvm does:
function prompt_fnm() {
local fnm_default
fnm_default=$(fnm list | grep default | awk '{ print $2 }') || return
local fnm_current=$(fnm current)
[[ $fnm_default != $fnm_current ]] || return
p10k segment -b 'magenta' -f 'black' -i 'NODE_ICON' -r -t "$fnm_current"
}
EDIT: see my issue in the fnm repo. Simply placing the eval statement from fnm above powerlevel10k at the top of your .zshrc solves the issue
Hey folks is anyone else having any issues with instant prompt and fnm? I can start a new issue for this, but I figured it was relevant within this existing fnm thread.
When you initialize a zsh session in a directory with a specified node-version, fnm outputs Using Node v{version} in color. I suspect color might be the cause of the issue here? fnm is not prompting for anything here, so I don't understand why it would cause issues with instant prompt.
I have an open issue with fnm here to determine if something can be changed on their end.
Last login: Mon Jun 6 16:32:28 on ttys000
[WARNING]: Console output during zsh initialization detected.
When using Powerlevel10k with instant prompt, console output during zsh
initialization may indicate issues.
You can:
- Recommended: Change ~/.zshrc so that it does not perform console I/O
after the instant prompt preamble. See the link below for details.
* You will not see this error message again.
* Zsh will start quickly and prompt will update smoothly.
- Suppress this warning either by running p10k configure or by manually
defining the following parameter:
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
* You will not see this error message again.
* Zsh will start quickly but prompt will jump down after initialization.
- Disable instant prompt either by running p10k configure or by manually
defining the following parameter:
typeset -g POWERLEVEL9K_INSTANT_PROMPT=off
* You will not see this error message again.
* Zsh will start slowly.
- Do nothing.
* You will see this error message every time you start zsh.
* Zsh will start quickly but prompt will jump down after initialization.
For details, see:
https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt
-- console output produced during zsh initialization follows --
Using Node v15.14.0
- How it should look
- The colorless output appearing under p10k error message
The warning links to https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt. Please check it out. If you cannot resolve the problem on your end, open a new issue and describe what you do (make sure to to specify all relevant config files), what you expect and what you observe.
Hi @romkatv, . I am using fnm, I uncomment node_version on .p10k.zsh, but it does not show up
Here is my entire .zshrc: https://codeshare.io/zyWg4r

Please open a separate issue.
I recently switched to
fnmand wrote this custom segment that does something close enough to whatprompt_nvmdoes:function prompt_fnm() { local fnm_default fnm_default=$(fnm list | grep default | awk '{ print $2 }') || return local fnm_current=$(fnm current) [[ $fnm_default != $fnm_current ]] || return p10k segment -b 'magenta' -f 'black' -i 'NODE_ICON' -r -t "$fnm_current" }
Worked like a charm, thanks!
If you don't want to create your own prompt, you can also do this workaround:
In your .zshrc for example, in the end of your file:
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
eval "$(fnm env --use-on-cd)" > /dev/null 2>&1
The > /dev/null 2>&1 is important, in order not to use the print of fnm.
And in your .p10k you just need to activate the node_version prompt. :)
@kud thanks for this!
Note, if anyone else trying to set this up with a terminal with black background, you'll need to get rid of the -f 'black' 😉