mirror of
https://github.com/ivuorinen/nvm-auto-use.fish.git
synced 2026-02-23 19:53:55 +00:00
Initial commit
This commit is contained in:
17
functions/nvm_auto_use.fish
Normal file
17
functions/nvm_auto_use.fish
Normal file
@@ -0,0 +1,17 @@
|
||||
function nvm_auto_use --on-variable PWD
|
||||
set -l nvmrc_file (nvm_find_nvmrc)
|
||||
if test -n "$nvmrc_file"
|
||||
set -l node_version (cat "$nvmrc_file")
|
||||
|
||||
# Check the current version
|
||||
set -l current_version (node -v 2>/dev/null | sed 's/v//')
|
||||
|
||||
if test "$node_version" != "$current_version"
|
||||
if not nvm use $node_version 2>/dev/null
|
||||
echo "Node.js version $node_version not found, installing..."
|
||||
nvm install $node_version && nvm use $node_version
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
11
functions/nvm_find_nvmrc.fish
Normal file
11
functions/nvm_find_nvmrc.fish
Normal file
@@ -0,0 +1,11 @@
|
||||
function nvm_find_nvmrc
|
||||
set -l dir (pwd)
|
||||
while test "$dir" != "/"
|
||||
if test -f "$dir/.nvmrc"
|
||||
echo "$dir/.nvmrc"
|
||||
return
|
||||
end
|
||||
set dir (dirname "$dir")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user