Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental NVM path caching #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions zsh-nvm.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,20 @@ _zsh_nvm_global_binaries() {

_zsh_nvm_load() {

if [[ "$NVM_CACHE_LOAD" == true ]]; then
# Strip out the old cached version of node that we were using.
export PATH="$(sed -e 's|[^:]*versions/node[^:]*[:]||g' <<< "$PATH")"
fi

# Source nvm (check if `nvm use` should be ran after load)
if [[ "$NVM_NO_USE" == true ]]; then
source "$NVM_DIR/nvm.sh" --no-use
else
source "$NVM_DIR/nvm.sh"
if [[ "$NVM_CACHE_LOAD" == true ]]; then
export NVM_CACHE_LOAD_PATH_NVM="$(awk -F ':' '{ print $1 }' <<< "$PATH")"
echo "$NVM_CACHE_LOAD_PATH_NVM" > "${HOME}/.zsh_nvm_cache"
fi
fi

# Rename main nvm function
Expand Down Expand Up @@ -72,6 +81,14 @@ _zsh_nvm_load() {
}

_zsh_nvm_lazy_load() {
if [[ "$NVM_CACHE_LOAD" == true ]] && [[ -s "${HOME}/.zsh_nvm_cache" ]]; then
export NVM_CACHE_LOAD_PATH_NVM="$(cat "${HOME}/.zsh_nvm_cache")"

# Add it to path if it doesn't already exist.
if [ -d "$NVM_CACHE_LOAD_PATH_NVM" ] && [[ ":$PATH:" != *":$NVM_CACHE_LOAD_PATH_NVM:"* ]]; then
export PATH="${NVM_CACHE_LOAD_PATH_NVM}${PATH:+":$PATH"}"
fi
fi

# Get all global node module binaries including node
# (only if NVM_NO_USE is off)
Expand Down