From 90972c478ff8509d58d20d1be0f7ff5f35d2c035 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Wed, 24 Jan 2024 21:33:45 -0500 Subject: [PATCH] Load nvm lazily --- fake_home/.zshrc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fake_home/.zshrc b/fake_home/.zshrc index eb7573c..4b78ba4 100644 --- a/fake_home/.zshrc +++ b/fake_home/.zshrc @@ -94,9 +94,22 @@ if test -d "$DOT_DIR" && [[ "$current_date" != "$(cat "$last_get_file")" ]] &> / getdot fi -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm -[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion +export nvm_loaded=false + +alias nvm="load_nvm; nvm" +alias node="load_nvm; node" + +function load_nvm { + if $nvm_loaded; then + return + fi + unalias nvm + unalias node + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + export nvm_loaded=true +} test -f /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh && source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh test -f "$HOME/.asdf/asdf.sh" && . "$HOME/.asdf/asdf.sh"