Skip to content

Commit

Permalink
Create $nvm_data if nonexistent on index update
Browse files Browse the repository at this point in the history
Close #185
  • Loading branch information
jorgebucaran committed May 31, 2022
1 parent 74c2201 commit 8449689
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions conf.d/nvm.fish
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function _nvm_install --on-event nvm_install
set --query nvm_mirror || set --universal nvm_mirror https://nodejs.org/dist
set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share
set --universal nvm_data $XDG_DATA_HOME/nvm
set --query nvm_mirror || set --universal nvm_mirror https://nodejs.org/dist

test ! -d $nvm_data && command mkdir -p $nvm_data
echo "Downloading the Node distribution index..." 2>/dev/null
_nvm_index_update $nvm_mirror $nvm_data/.index
_nvm_index_update
end

function _nvm_update --on-event nvm_update
set --query nvm_mirror || set --universal nvm_mirror https://nodejs.org/dist
set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share
set --universal nvm_data $XDG_DATA_HOME/nvm
set --query nvm_mirror || set --universal nvm_mirror https://nodejs.org/dist
end

function _nvm_uninstall --on-event nvm_uninstall
Expand Down
10 changes: 7 additions & 3 deletions functions/_nvm_index_update.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
function _nvm_index_update --argument-names mirror index
if not command curl --location --silent $mirror/index.tab >$index.temp
function _nvm_index_update
test ! -d $nvm_data && command mkdir -p $nvm_data

set --local index $nvm_data/.index

if not command curl --location --silent $nvm_mirror/index.tab >$index.temp
command rm -f $index.temp
echo "nvm: Can't update index, host unavailable: \"$mirror\"" >&2
echo "nvm: Can't update index, host unavailable: \"$nvm_mirror\"" >&2
return 1
end

Expand Down
4 changes: 2 additions & 2 deletions functions/nvm.fish
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function nvm --description "Node version manager"
echo " nvm_mirror Set the Node download mirror"
echo " nvm_default_version Set the default version for new shells"
case install
_nvm_index_update $nvm_mirror $nvm_data/.index || return
_nvm_index_update

string match --entire --regex -- (_nvm_version_match $ver) <$nvm_data/.index | read ver alias

Expand Down Expand Up @@ -170,7 +170,7 @@ function nvm --description "Node version manager"
case ls list
_nvm_list | _nvm_list_format (_nvm_current) $argv[2]
case lsr {ls,list}-remote
_nvm_index_update $nvm_mirror $nvm_data/.index || return
_nvm_index_update || return
_nvm_list | command awk '
FILENAME == "-" && (is_local[$1] = FNR == NR) { next } {
print $0 (is_local[$1] ? " ✓" : "")
Expand Down

0 comments on commit 8449689

Please sign in to comment.