问题
I use nvm
and want to find out which version of node is currently running.
If the system
version is being used, I want to see the string system
.
Ideally, I'm looking for a string to put in my prompt.
回答1:
run this in terminal
nvm current
or
node -v
nvm ls
for list all version
nvm use version_name
for use that version
回答2:
In bash
:
[[ $NVM_BIN =~ ([^/]+)/bin$ ]] && echo "${BASH_REMATCH[2]}" || echo "system"
For zsh
, first do:
setopt BASH_REMATCH
This is much faster than using nvm current
, especially for use in a prompt:
$ time nvm current
system
real 0m0.188s
user 0m0.149s
sys 0m0.042s
Compared with:
$ time [[ $NVM_BIN =~ ([^/]+)/bin$ ]] && echo "${BASH_REMATCH[2]}" || echo "system"
real 0m0.009s
user 0m0.002s
sys 0m0.007s
system
Almost 0.2 seconds vs only 0.009 seconds.
来源:https://stackoverflow.com/questions/53039287/how-do-i-find-the-currently-activated-version-with-nvm