bullet-train.zsh icon indicating copy to clipboard operation
bullet-train.zsh copied to clipboard

make node segment not cause errors without requiring manual configuration by the user

Open hvindin opened this issue 7 years ago • 2 comments

related to #212

hvindin avatar Jun 14 '17 03:06 hvindin

The code suggested with this PR is not working for me. However below works on my laptop

# NVM: Node version manager
prompt_nvm() {
  if (( ! $+commands[node] )); then
    return      
  fi
  local nvm_prompt
  if type nvm >/dev/null 2>&1; then
    nvm_prompt=$(nvm current 2>/dev/null)
    [[ "${nvm_prompt}x" == "x" ]] && return
  elif hash node &> /dev/null; then
    nvm_prompt="$(node --version)"
  fi
  nvm_prompt=${nvm_prompt}
  if [[ -n "${nvm_prompt}" ]]; then
    prompt_segment $BULLETTRAIN_NVM_BG $BULLETTRAIN_NVM_FG $BULLETTRAIN_NVM_PREFIX$nvm_prompt
  fi
}

as it was suggested by @ddnexus at #212

quater avatar Jun 24 '17 14:06 quater

Interesting, what version of zsh are you running?/what os are you running? works fine for me with:

zsh 5.3.1 (x86_64-redhat-linux-gnu)

But presumably there might be some differences.

If the (( ! $+commands[node] )) style check works more universally then perhaps my latest crack at this might be better suited. Rather than just exiting out if node is not found it follows the same logic as the original code but used (( $+commands[node] )) and (( $+commands[nvm] )) to figure out if nvm or node are installed sequentially then just doesn't set the nvm_prompt if neither exist.

hvindin avatar Jun 27 '17 21:06 hvindin