prezto/modules/node/init.zsh
Indrajit Raychaudhuri 9f37fc9841 node: Optimize completions for loading lazily on demand
Move `grunt` and `gulp` to separate completion definitions wrapping
`grunt --completion=zsh` and `gulp --completion=zsh` respectively.

Since the completions are loaded lazily on demand, they avoid the
performance overhead during Zsh initialization.

Additionally, remove `npm` completion since it is already bundled with
Zsh for quite a while.
2021-05-21 13:39:23 -05:00

40 lines
1.3 KiB
Bash

#
# Configures Node local installation, loads version managers, and defines
# variables and aliases.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
# Zeh Rizzatti <zehrizzatti@gmail.com>
# Indrajit Raychaudhuri <irc@indrajit.com>
#
# Possible lookup locations.
local_nodenv_paths=({$NODENV_ROOT,{$XDG_CONFIG_HOME/,$HOME/.}nodenv}/bin/nodenv(N))
local_nvm_paths=({$NVM_DIR,{$XDG_CONFIG_HOME/,$HOME/.}nvm}/nvm.sh(N))
# Load manually installed nodenv into the shell session.
if [[ -s ${local_nodenv::=$local_nodenv_paths[1]} ]]; then
path=("$local_nodenv:h" $path)
eval "$(nodenv init - --no-rehash zsh)"
unset local_nodenv{,_paths}
# Load package manager installed nodenv into the shell session.
elif (( $+commands[nodenv] )); then
eval "$(nodenv init - --no-rehash zsh)"
# Load manually installed NVM into the shell session.
elif [[ -s ${local_nvm::=$local_nvm_paths[1]} ]]; then
source "$local_nvm --no-use"
unset local_nvm{,_paths}
# Load package manager installed NVM into the shell session.
elif (( $+commands[brew] )) \
&& [[ -d "${nvm_prefix::="$(brew --prefix nvm 2> /dev/null)"}" ]]; then
source "$nvm_prefix/nvm.sh --no-use"
unset nvm_prefix
# Return if requirements are not found.
elif (( ! $+commands[node] )); then
return 1
fi