Skip to content

Commit

Permalink
Load nvm async
Browse files Browse the repository at this point in the history
Nvm was the slowest part of my prompt. Opening a new shell is super
quick now.

Reference: nvm-sh/nvm#539 (comment)
  • Loading branch information
MarcelRobitaille committed Jun 3, 2020
1 parent cdfa287 commit 687ec18
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions zsh/.zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ DEFAULT_USER="marcel"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh


#
# Load nvm
#

export NVM_DIR="$HOME/.nvm"

# Async function
function load_nvm() {
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
}

# Call `load_nvm` in async worker
async_start_worker nvm_worker -n
async_register_callback nvm_worker load_nvm
async_job nvm_worker sleep 0.1

# Up/down search for matches of what's already there
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
Expand All @@ -34,10 +51,4 @@ bindkey '^N' down-line-or-beginning-search
bindkey '^[[A' up-line-or-beginning-search
bindkey '^[[B' down-line-or-beginning-search

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

bindkey -v
[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh

0 comments on commit 687ec18

Please sign in to comment.