From fdf4d6cc7df56b8540363ba2984178642c8b7ca7 Mon Sep 17 00:00:00 2001 From: Alexandre Faria <16895682+lusoalex@users.noreply.github.com> Date: Fri, 1 May 2020 12:42:28 +0200 Subject: [PATCH] Add NVM_COMPLETION option (#63) --- README.md | 12 ++++++++++++ zsh-nvm.plugin.zsh | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index e50e32a..6659795 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,18 @@ antigen bundle lukechilds/zsh-nvm Note: If `nvm` doesn't exist in this directory it'll be automatically installed when you start a session. +### Nvm Completion + +`nvm` comes with a default bash_completion profile. If you want to enable it, you can do it by exporting the `NVM_COMPLETION` environment variable and setting it to `true`. It must be set before `zsh-nvm` is loaded. + +For example, if you are using antigen, you would put the following in your `.zshrc`: + +```bash +# Export nvm completion settings for zsh-nvm plugin +export NVM_COMPLETION=true +antigen bundle lukechilds/zsh-nvm +``` + ### Lazy Loading If you find `nvm` adds too much lag to your shell startup you can enable lazy loading by exporting the `NVM_LAZY_LOAD` environment variable and setting it to `true`. It must be set before `zsh-nvm` is loaded. diff --git a/zsh-nvm.plugin.zsh b/zsh-nvm.plugin.zsh index efe068b..9c64c44 100644 --- a/zsh-nvm.plugin.zsh +++ b/zsh-nvm.plugin.zsh @@ -71,6 +71,12 @@ _zsh_nvm_load() { } } +_zsh_nvm_completion() { + + # Add provided nvm completion + [[ -r $NVM_DIR/bash_completion ]] && source $NVM_DIR/bash_completion +} + _zsh_nvm_lazy_load() { # Get all global node module binaries including node @@ -207,6 +213,9 @@ if [[ "$ZSH_NVM_NO_LOAD" != true ]]; then # Load it [[ "$NVM_LAZY_LOAD" == true ]] && _zsh_nvm_lazy_load || _zsh_nvm_load + # Enable completion + [[ "$NVM_COMPLETION" == true ]] && _zsh_nvm_completion + # Auto use nvm on chpwd [[ "$NVM_AUTO_USE" == true ]] && add-zsh-hook chpwd _zsh_nvm_auto_use && _zsh_nvm_auto_use fi