mirror of
https://github.com/lukechilds/zsh-nvm.git
synced 2025-02-06 09:55:31 +08:00
Add experimental NVM path caching
This commit is contained in:
parent
2d88fd5c8f
commit
1f03039e85
@ -38,11 +38,20 @@ _zsh_nvm_global_binaries() {
|
|||||||
|
|
||||||
_zsh_nvm_load() {
|
_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)
|
# Source nvm (check if `nvm use` should be ran after load)
|
||||||
if [[ "$NVM_NO_USE" == true ]]; then
|
if [[ "$NVM_NO_USE" == true ]]; then
|
||||||
source "$NVM_DIR/nvm.sh" --no-use
|
source "$NVM_DIR/nvm.sh" --no-use
|
||||||
else
|
else
|
||||||
source "$NVM_DIR/nvm.sh"
|
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
|
fi
|
||||||
|
|
||||||
# Rename main nvm function
|
# Rename main nvm function
|
||||||
@ -72,7 +81,15 @@ _zsh_nvm_load() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_zsh_nvm_lazy_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="${PATH:+"$PATH:"}${NVM_CACHE_LOAD_PATH_NVM}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Get all global node module binaries including node
|
# Get all global node module binaries including node
|
||||||
# (only if NVM_NO_USE is off)
|
# (only if NVM_NO_USE is off)
|
||||||
local global_binaries
|
local global_binaries
|
||||||
|
Loading…
Reference in New Issue
Block a user