-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rewrite for Fish 3.0. - Use More consistent command-line interface. - Don't mutate global node so that activating a version only lasts for the lifetime of the current shell. - Introduce the nvm_default_version variable to persist a Node version system-wide. - Use XDG_DATA_HOME. - Switch to GitHub Actions. - Write new docs.
- Loading branch information
1 parent
2975358
commit 4b3c5bf
Showing
9 changed files
with
290 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
complete -xc nvm -n __fish_use_subcommand -a ls -d "List available versions matching <regex>" | ||
complete -xc nvm -n __fish_use_subcommand -a use -d "Download <version> and modify PATH so it's available" | ||
complete -xc nvm -n __fish_use_subcommand -a --help -d "Show usage help" | ||
complete -xc nvm -n __fish_use_subcommand -a --version -d "Show the current version of nvm" | ||
complete -c nvm --exclusive --long version -d "Print nvm version" | ||
complete -c nvm --exclusive --long help -d "Print this help message" | ||
|
||
nvm complete | ||
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a install -d "Download and activate a given version (use nearest .nvmrc file if none is given)" | ||
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a use -d "Activate a version in the current shell" | ||
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a list -d "List installed versions" | ||
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a list-remote -d "List versions available to install (matching optional regex)" | ||
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a current -d "Print currently-active version" | ||
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from install" -a "( | ||
test -e $nvm_data && string split ' ' <$nvm_data/.index | ||
)" | ||
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from use" -a "(_nvm_list | string split ' ')" | ||
complete -c nvm --exclusive --condition "__fish_use_subcommand" -a uninstall -d "Uninstall a version" | ||
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from uninstall" -a "( | ||
_nvm_list | string split ' ' | string replace system '' | ||
)" | ||
complete -c nvm --exclusive --condition "__fish_seen_subcommand_from use uninstall" -a "( | ||
set --query nvm_default_version && echo default | ||
)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
function _nvm_uninstall -e nvm_uninstall | ||
if test -s "$nvm_config/version" | ||
read -l ver <$nvm_config/version | ||
if set -l i (contains -i -- "$nvm_config/$ver/bin" $fish_user_paths) | ||
set -e fish_user_paths[$i] | ||
end | ||
command rm -f $nvm_config/version | ||
end | ||
|
||
for name in (set -n | command awk '/^nvm_/') | ||
set -e "$name" | ||
end | ||
|
||
functions -e (functions -a | command awk '/^_nvm_/') | ||
set --global nvm_version 2.0.0 | ||
|
||
set --query XDG_DATA_HOME \ | ||
&& set --global nvm_data $XDG_DATA_HOME/nvm \ | ||
|| set --global nvm_data ~/.local/share/nvm | ||
set --query nvm_mirror || set --global nvm_mirror https://nodejs.org/dist | ||
|
||
if set --query nvm_default_version && ! set --query nvm_current_version | ||
nvm use $nvm_default_version >/dev/null | ||
end | ||
|
||
function _nvm_install -e nvm_install | ||
test ! -d $nvm_data && command mkdir -p $nvm_data | ||
echo "Downloading the Node distribution index for the first time..." 2>/dev/null | ||
_nvm_index_update $nvm_mirror/index.tab $nvm_data/.index | ||
end | ||
|
||
function _nvm_uninstall -e nvm_uninstall | ||
command rm -rf $nvm_data | ||
set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version | ||
|
||
set --names | string replace --filter --regex "^nvm_" -- "set --erase nvm_" | source | ||
functions --erase (functions --all | string match --entire --regex "^_nvm_") | ||
complete --erase --command nvm | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function _nvm_index_update -a mirror index | ||
command curl --location --silent $mirror | command awk -v OFS=\t ' | ||
/v0.9.12/ { exit } # Unsupported | ||
NR > 1 { | ||
print $1 (NR == 2 ? " latest" : $10 != "-" ? " lts/" tolower($10) : "") | ||
} | ||
' > $index.temp && command mv $index.temp $index && return | ||
|
||
command rm -f $index.temp | ||
echo "nvm: Invalid index or unavailable host: \"$mirror\"" >&2 | ||
return 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
function _nvm_list | ||
set --local versions $nvm_data/* | ||
set --query versions[1] \ | ||
&& string match --entire --regex (string match --regex "v\d.+" $versions \ | ||
| string escape --style=regex \ | ||
| string join "|" | ||
) <$nvm_data/.index | ||
|
||
command --all node | string match --quiet --invert --regex "^$nvm_data" \ | ||
&& echo system | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function _nvm_version_activate -a v | ||
set --global --export nvm_current_version $v | ||
set --prepend PATH $nvm_data/$v/bin | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function _nvm_version_deactivate -a v | ||
test "$nvm_current_version" = "$v" && set --erase nvm_current_version | ||
set --local index (contains --index -- $nvm_data/$v/bin $PATH) \ | ||
&& set --erase PATH[$index] | ||
end |
Oops, something went wrong.