Skip to content

Commit 80cd868

Browse files
committed
Add nvm uset default when default is set
1 parent 931efb3 commit 80cd868

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

conf.d/nvm.fish

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,28 @@ function applyNvmRcUse
3030
# No nvmrc file found.
3131
if test $nvmrc_applied != "N/A"
3232
# nvmrc was applied, but no nvmrc file found.
33+
34+
# We know that we will uset the variable.
35+
set -g nvmrc_applied "N/A"
36+
37+
useDefaultNVMVersion
38+
if test "$nvm_use_default_status" = "0"
39+
return
40+
end
41+
3342
# Unload nvm.
3443
__nvm unload
35-
set -g nvmrc_applied "N/A"
3644
set -g nvmrc_node_version "N/A"
3745

3846
if test $nvmrc_announce = "yes"
3947
echo "nvmrc: Unloaded nvm."
4048
end
49+
50+
return
51+
end
52+
53+
if test $nvmrc_node_version = "N/A"
54+
useDefaultNVMVersion
4155
end
4256

4357
return
@@ -49,7 +63,7 @@ function applyNvmRcUse
4963
return
5064
end
5165

52-
set -l __nvmrc_node_version (nvm version (cat $__nvmrc_file))
66+
set -l __nvmrc_node_version (__nvm version (cat $__nvmrc_file))
5367
# nvmrc file found.
5468
if test $__nvmrc_node_version = "N/A"
5569
# nvmrc file specifies a version that nvm does not have installed.
@@ -79,6 +93,21 @@ function applyNvmRcUse
7993
end
8094
end
8195

96+
# Apply default node version, we do not want to install default version.
97+
function useDefaultNVMVersion
98+
# Try to use default version.
99+
__nvm use default --silent
100+
101+
set -g nvm_use_default_status $status
102+
if test "$nvm_use_default_status" = "0"
103+
# Default version is set.
104+
set -g nvmrc_node_version (__nvm version)
105+
if test $nvmrc_announce = "yes"
106+
echo "nvmrc: Loaded default node version $nvmrc_node_version"
107+
end
108+
end
109+
end
110+
82111
# We need to run applyNvmRcUse on the initialization of each session.
83112
if status is-interactive
84113
# Set nvmrc_applied to default "N/A" value if not set.

0 commit comments

Comments
 (0)