Skip to content

Instantly share code, notes, and snippets.

@wayou
Created August 19, 2025 12:44
Show Gist options
  • Save wayou/cbe7853ba7971d28e27ad50efd28cbab to your computer and use it in GitHub Desktop.
Save wayou/cbe7853ba7971d28e27ad50efd28cbab to your computer and use it in GitHub Desktop.
Fish Shell NVM Lazy Loading Setup Guide

Fish Shell NVM Lazy Loading Setup

Goal

Make nvm lazy load to speed up terminal startup while keeping full functionality.

Changes Made

1. System Default Node.js Setup

Create symlinks to make nvm-installed Node.js v23.7.0 the system default:

sudo ln -sf ~/.nvm/versions/node/v23.7.0/bin/node /usr/local/bin/node
sudo ln -sf ~/.nvm/versions/node/v23.7.0/bin/npm /usr/local/bin/npm  
sudo ln -sf ~/.nvm/versions/node/v23.7.0/bin/npx /usr/local/bin/npx

2. Install Bass Plugin

Add edc/bass plugin via fisher for bash-fish integration:

curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source
fisher install edc/bass

3. Replace NVM Initialization in ~/.config/fish/config.fish

Remove: Immediate nvm initialization that ran on every terminal startup:

load_nvm > /dev/stderr

# Initialize nvm and use default version on startup
if status is-interactive
    nvm use default > /dev/null 2>&1
end

Add: Lazy loading nvm function that only loads when nvm commands are used:

# Lazy load nvm - direct bash wrapper
function nvm
    set -l cmd "source ~/.nvm/nvm.sh && nvm"
    for arg in $argv
        set cmd "$cmd '$arg'"
    end
    bash -c "$cmd"
end

4. Update ~/.config/fish/functions/load_nvm.fish

Replace the entire function with a pure fish implementation:

function load_nvm --on-variable="PWD"
  # Find .nvmrc file
  set -l nvmrc_path
  set -l current_dir (pwd)
  while test "$current_dir" != "/"
    if test -f "$current_dir/.nvmrc"
      set nvmrc_path "$current_dir/.nvmrc"
      break
    end
    set current_dir (dirname "$current_dir")
  end
  
  if test -n "$nvmrc_path"
    set -l nvmrc_version (cat "$nvmrc_path" | string trim)
    echo "Found .nvmrc with version: $nvmrc_version"
    nvm use "$nvmrc_version"
  end
end

Result

  • Fast startup: Terminal opens instantly without nvm initialization delay
  • Full nvm functionality: All nvm commands work normally when explicitly called
  • Auto version switching: Still switches Node versions when entering directories with .nvmrc
  • System default: Node.js v23.7.0 available immediately for all scripts

Usage

  • node --version - Uses system default (instant)
  • nvm --version - Lazy loads nvm first time, then works normally
  • cd project-with-nvmrc - Auto-switches to project's Node version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment