lib/nvm: Use which nvm and nvm current

This makes it work regardless of where nvm is loaded from. And it uses nvm's version strings, which distinguish the "system" and "none" NVM environments, instead of reporting the specific version of the system node.js or erroring, respectively.
This commit is contained in:
Andrew Janke 2015-09-10 04:10:18 -04:00 committed by janke
commit e391fd94a7

View file

@ -1,9 +1,9 @@
# get the node.js version # get the nvm-controlled node.js version
function nvm_prompt_info() { function nvm_prompt_info() {
[[ -f "$NVM_DIR/nvm.sh" ]] || return [[ -f "$NVM_DIR/nvm.sh" ]] || return
local nvm_prompt local nvm_prompt
nvm_prompt=$(node -v 2>/dev/null) which nvm &>/dev/null || return
[[ "${nvm_prompt}x" == "x" ]] && return nvm_prompt=$(nvm current)
nvm_prompt=${nvm_prompt:1} nvm_prompt=${nvm_prompt#v}
echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}" echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
} }