aboutsummaryrefslogtreecommitdiff
path: root/.config
diff options
context:
space:
mode:
authorGuangxiong Lin <[email protected]>2023-11-15 08:58:19 +0800
committerGuangxiong Lin <[email protected]>2023-11-15 08:58:19 +0800
commit016c96d8af4c944fb2b9fc0c673f5130472a7977 (patch)
treeb8410f3cea2780043d66a67a8b1e173930488bed /.config
parent55c2d8e73db4e9e93cddcb981c15fb8fe9b1dcf4 (diff)
downloaddotfiles-016c96d8af4c944fb2b9fc0c673f5130472a7977.tar.gz
dotfiles-016c96d8af4c944fb2b9fc0c673f5130472a7977.tar.bz2
dotfiles-016c96d8af4c944fb2b9fc0c673f5130472a7977.zip
Update aliases and add fisher
Diffstat (limited to '.config')
-rw-r--r--.config/fish/completions/fisher.fish7
-rw-r--r--.config/fish/completions/nvm.fish21
-rw-r--r--.config/fish/conf.d/nvm.fish28
-rw-r--r--.config/fish/config.fish5
-rw-r--r--.config/fish/fish_plugins2
-rw-r--r--.config/fish/fish_variables5
-rw-r--r--.config/fish/functions/_nvm_index_update.fish20
-rw-r--r--.config/fish/functions/_nvm_list.fish11
-rw-r--r--.config/fish/functions/_nvm_version_activate.fish4
-rw-r--r--.config/fish/functions/_nvm_version_deactivate.fish5
-rw-r--r--.config/fish/functions/fisher.fish240
-rw-r--r--.config/fish/functions/nvm.fish234
12 files changed, 582 insertions, 0 deletions
diff --git a/.config/fish/completions/fisher.fish b/.config/fish/completions/fisher.fish
new file mode 100644
index 0000000..6d23ce4
--- /dev/null
+++ b/.config/fish/completions/fisher.fish
@@ -0,0 +1,7 @@
+complete --command fisher --exclusive --long help --description "Print help"
+complete --command fisher --exclusive --long version --description "Print version"
+complete --command fisher --exclusive --condition __fish_use_subcommand --arguments install --description "Install plugins"
+complete --command fisher --exclusive --condition __fish_use_subcommand --arguments update --description "Update installed plugins"
+complete --command fisher --exclusive --condition __fish_use_subcommand --arguments remove --description "Remove installed plugins"
+complete --command fisher --exclusive --condition __fish_use_subcommand --arguments list --description "List installed plugins matching regex"
+complete --command fisher --exclusive --condition "__fish_seen_subcommand_from update remove" --arguments "(fisher list)"
diff --git a/.config/fish/completions/nvm.fish b/.config/fish/completions/nvm.fish
new file mode 100644
index 0000000..14be1b7
--- /dev/null
+++ b/.config/fish/completions/nvm.fish
@@ -0,0 +1,21 @@
+complete --command nvm --exclusive
+complete --command nvm --exclusive --long version --description "Print version"
+complete --command nvm --exclusive --long help --description "Print help"
+complete --command nvm --long silent --description "Suppress standard output"
+
+complete --command nvm --exclusive --condition __fish_use_subcommand --arguments install --description "Download and activate the specified Node version"
+complete --command nvm --exclusive --condition __fish_use_subcommand --arguments use --description "Activate the specified Node version in the current shell"
+complete --command nvm --exclusive --condition __fish_use_subcommand --arguments list --description "List installed Node versions"
+complete --command nvm --exclusive --condition __fish_use_subcommand --arguments list-remote --description "List available Node versions to install"
+complete --command nvm --exclusive --condition __fish_use_subcommand --arguments current --description "Print the currently-active Node version"
+complete --command nvm --exclusive --condition "__fish_seen_subcommand_from install" --arguments "(
+ test -e $nvm_data && string split ' ' <$nvm_data/.index
+)"
+complete --command nvm --exclusive --condition "__fish_seen_subcommand_from use" --arguments "(_nvm_list | string split ' ')"
+complete --command nvm --exclusive --condition __fish_use_subcommand --arguments uninstall --description "Uninstall the specified Node version"
+complete --command nvm --exclusive --condition "__fish_seen_subcommand_from uninstall" --arguments "(
+ _nvm_list | string split ' ' | string replace system ''
+)"
+complete --command nvm --exclusive --condition "__fish_seen_subcommand_from use uninstall" --arguments "(
+ set --query nvm_default_version && echo default
+)"
diff --git a/.config/fish/conf.d/nvm.fish b/.config/fish/conf.d/nvm.fish
new file mode 100644
index 0000000..e060f2f
--- /dev/null
+++ b/.config/fish/conf.d/nvm.fish
@@ -0,0 +1,28 @@
+set --query nvm_mirror || set --global nvm_mirror https://nodejs.org/dist
+set --query XDG_DATA_HOME || set --local XDG_DATA_HOME ~/.local/share
+set --global nvm_data $XDG_DATA_HOME/nvm
+
+function _nvm_install --on-event nvm_install
+ test ! -d $nvm_data && command mkdir -p $nvm_data
+ echo "Downloading the Node distribution index..." 2>/dev/null
+ _nvm_index_update
+end
+
+function _nvm_update --on-event nvm_update
+ set --query --universal nvm_data && set --erase --universal nvm_data
+ set --query --universal nvm_mirror && set --erase --universal nvm_mirror
+ set --query nvm_mirror || set --global nvm_mirror https://nodejs.org/dist
+end
+
+function _nvm_uninstall --on-event 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_")
+end
+
+if status is-interactive && set --query nvm_default_version && ! set --query nvm_current_version
+ nvm use --silent $nvm_default_version
+end
diff --git a/.config/fish/config.fish b/.config/fish/config.fish
index 4414fb7..14c8150 100644
--- a/.config/fish/config.fish
+++ b/.config/fish/config.fish
@@ -1,4 +1,5 @@
if status is-interactive
+ set -U fish_greeting
command -v zoxide > /dev/null && zoxide init --cmd j fish | source
command -v navi > /dev/null && eval "$(navi widget fish)"
init_fzf
@@ -13,4 +14,8 @@ if status is-interactive
command -v tig > /dev/null && function tigs; tig status; end
command -v git > /dev/null && function g; git $argv; end
+
+ source "$HOME/.aliases"
+
+ [ -r "$HOME/.local_config.fish" ] && source "$HOME/.local_config.fish"
end
diff --git a/.config/fish/fish_plugins b/.config/fish/fish_plugins
new file mode 100644
index 0000000..9673b42
--- /dev/null
+++ b/.config/fish/fish_plugins
@@ -0,0 +1,2 @@
+jorgebucaran/fisher
+jorgebucaran/nvm.fish
diff --git a/.config/fish/fish_variables b/.config/fish/fish_variables
index 1a82b8a..2e064e3 100644
--- a/.config/fish/fish_variables
+++ b/.config/fish/fish_variables
@@ -1,6 +1,10 @@
# This file contains fish universal variable definitions.
# VERSION: 3.0
SETUVAR __fish_initialized:3400
+SETUVAR _fisher_jorgebucaran_2F_fisher_files:\x7e/\x2econfig/fish/functions/fisher\x2efish\x1e\x7e/\x2econfig/fish/completions/fisher\x2efish
+SETUVAR _fisher_jorgebucaran_2F_nvm_2E_fish_files:\x7e/\x2econfig/fish/functions/_nvm_index_update\x2efish\x1e\x7e/\x2econfig/fish/functions/_nvm_list\x2efish\x1e\x7e/\x2econfig/fish/functions/_nvm_version_activate\x2efish\x1e\x7e/\x2econfig/fish/functions/_nvm_version_deactivate\x2efish\x1e\x7e/\x2econfig/fish/functions/nvm\x2efish\x1e\x7e/\x2econfig/fish/conf\x2ed/nvm\x2efish\x1e\x7e/\x2econfig/fish/completions/nvm\x2efish
+SETUVAR _fisher_plugins:jorgebucaran/fisher\x1ejorgebucaran/nvm\x2efish
+SETUVAR _fisher_upgraded_to_4_4:\x1d
SETUVAR fish_color_autosuggestion:555\x1ebrblack
SETUVAR fish_color_cancel:\x2dr
SETUVAR fish_color_command:blue
@@ -23,6 +27,7 @@ SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrbl
SETUVAR fish_color_status:red
SETUVAR fish_color_user:brgreen
SETUVAR fish_color_valid_path:\x2d\x2dunderline
+SETUVAR fish_greeting:\x1d
SETUVAR fish_key_bindings:fish_default_key_bindings
SETUVAR fish_pager_color_completion:normal
SETUVAR fish_pager_color_description:B3A06D\x1eyellow\x1e\x2di
diff --git a/.config/fish/functions/_nvm_index_update.fish b/.config/fish/functions/_nvm_index_update.fish
new file mode 100644
index 0000000..c1bbe28
--- /dev/null
+++ b/.config/fish/functions/_nvm_index_update.fish
@@ -0,0 +1,20 @@
+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: \"$nvm_mirror\"" >&2
+ return 1
+ end
+
+ command awk -v OFS=\t '
+ /v0.9.12/ { exit } # Unsupported
+ NR > 1 {
+ print $1 (NR == 2 ? " latest" : $10 != "-" ? " lts/" tolower($10) : "")
+ }
+ ' $index.temp >$index
+
+ command rm -f $index.temp
+end
diff --git a/.config/fish/functions/_nvm_list.fish b/.config/fish/functions/_nvm_list.fish
new file mode 100644
index 0000000..fb5ab0e
--- /dev/null
+++ b/.config/fish/functions/_nvm_list.fish
@@ -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
diff --git a/.config/fish/functions/_nvm_version_activate.fish b/.config/fish/functions/_nvm_version_activate.fish
new file mode 100644
index 0000000..f7dfef7
--- /dev/null
+++ b/.config/fish/functions/_nvm_version_activate.fish
@@ -0,0 +1,4 @@
+function _nvm_version_activate --argument-names ver
+ set --global --export nvm_current_version $ver
+ set --prepend PATH $nvm_data/$ver/bin
+end
diff --git a/.config/fish/functions/_nvm_version_deactivate.fish b/.config/fish/functions/_nvm_version_deactivate.fish
new file mode 100644
index 0000000..24dd36e
--- /dev/null
+++ b/.config/fish/functions/_nvm_version_deactivate.fish
@@ -0,0 +1,5 @@
+function _nvm_version_deactivate --argument-names ver
+ test "$nvm_current_version" = "$ver" && set --erase nvm_current_version
+ set --local index (contains --index -- $nvm_data/$ver/bin $PATH) &&
+ set --erase PATH[$index]
+end
diff --git a/.config/fish/functions/fisher.fish b/.config/fish/functions/fisher.fish
new file mode 100644
index 0000000..b1513d3
--- /dev/null
+++ b/.config/fish/functions/fisher.fish
@@ -0,0 +1,240 @@
+function fisher --argument-names cmd --description "A plugin manager for Fish"
+ set --query fisher_path || set --local fisher_path $__fish_config_dir
+ set --local fisher_version 4.4.4
+ set --local fish_plugins $__fish_config_dir/fish_plugins
+
+ switch "$cmd"
+ case -v --version
+ echo "fisher, version $fisher_version"
+ case "" -h --help
+ echo "Usage: fisher install <plugins...> Install plugins"
+ echo " fisher remove <plugins...> Remove installed plugins"
+ echo " fisher update <plugins...> Update installed plugins"
+ echo " fisher update Update all installed plugins"
+ echo " fisher list [<regex>] List installed plugins matching regex"
+ echo "Options:"
+ echo " -v, --version Print version"
+ echo " -h, --help Print this help message"
+ echo "Variables:"
+ echo " \$fisher_path Plugin installation path. Default: $__fish_config_dir" | string replace --regex -- $HOME \~
+ case ls list
+ string match --entire --regex -- "$argv[2]" $_fisher_plugins
+ case install update remove
+ isatty || read --local --null --array stdin && set --append argv $stdin
+
+ set --local install_plugins
+ set --local update_plugins
+ set --local remove_plugins
+ set --local arg_plugins $argv[2..-1]
+ set --local old_plugins $_fisher_plugins
+ set --local new_plugins
+
+ test -e $fish_plugins && set --local file_plugins (string match --regex -- '^[^\s]+$' <$fish_plugins)
+
+ if ! set --query argv[2]
+ if test "$cmd" != update
+ echo "fisher: Not enough arguments for command: \"$cmd\"" >&2 && return 1
+ else if ! set --query file_plugins
+ echo "fisher: \"$fish_plugins\" file not found: \"$cmd\"" >&2 && return 1
+ end
+ set arg_plugins $file_plugins
+ end
+
+ for plugin in $arg_plugins
+ set plugin (test -e "$plugin" && realpath $plugin || string lower -- $plugin)
+ contains -- "$plugin" $new_plugins || set --append new_plugins $plugin
+ end
+
+ if set --query argv[2]
+ for plugin in $new_plugins
+ if contains -- "$plugin" $old_plugins
+ test "$cmd" = remove &&
+ set --append remove_plugins $plugin ||
+ set --append update_plugins $plugin
+ else if test "$cmd" = install
+ set --append install_plugins $plugin
+ else
+ echo "fisher: Plugin not installed: \"$plugin\"" >&2 && return 1
+ end
+ end
+ else
+ for plugin in $new_plugins
+ contains -- "$plugin" $old_plugins &&
+ set --append update_plugins $plugin ||
+ set --append install_plugins $plugin
+ end
+
+ for plugin in $old_plugins
+ contains -- "$plugin" $new_plugins || set --append remove_plugins $plugin
+ end
+ end
+
+ set --local pid_list
+ set --local source_plugins
+ set --local fetch_plugins $update_plugins $install_plugins
+ set --local fish_path (status fish-path)
+
+ echo (set_color --bold)fisher $cmd version $fisher_version(set_color normal)
+
+ for plugin in $fetch_plugins
+ set --local source (command mktemp -d)
+ set --append source_plugins $source
+
+ command mkdir -p $source/{completions,conf.d,themes,functions}
+
+ $fish_path --command "
+ if test -e $plugin
+ command cp -Rf $plugin/* $source
+ else
+ set temp (command mktemp -d)
+ set repo (string split -- \@ $plugin) || set repo[2] HEAD
+
+ if set path (string replace --regex -- '^(https://)?gitlab.com/' '' \$repo[1])
+ set name (string split -- / \$path)[-1]
+ set url https://gitlab.com/\$path/-/archive/\$repo[2]/\$name-\$repo[2].tar.gz
+ else
+ set url https://api.github.com/repos/\$repo[1]/tarball/\$repo[2]
+ end
+
+ echo Fetching (set_color --underline)\$url(set_color normal)
+
+ if command curl -q --silent -L \$url | command tar -xzC \$temp -f - 2>/dev/null
+ command cp -Rf \$temp/*/* $source
+ else
+ echo fisher: Invalid plugin name or host unavailable: \\\"$plugin\\\" >&2
+ command rm -rf $source
+ end
+
+ command rm -rf \$temp
+ end
+
+ set files $source/* && string match --quiet --regex -- .+\.fish\\\$ \$files
+ " &
+
+ set --append pid_list (jobs --last --pid)
+ end
+
+ wait $pid_list 2>/dev/null
+
+ for plugin in $fetch_plugins
+ if set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)] && test ! -e $source
+ if set --local index (contains --index -- "$plugin" $install_plugins)
+ set --erase install_plugins[$index]
+ else
+ set --erase update_plugins[(contains --index -- "$plugin" $update_plugins)]
+ end
+ end
+ end
+
+ for plugin in $update_plugins $remove_plugins
+ if set --local index (contains --index -- "$plugin" $_fisher_plugins)
+ set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files
+
+ if contains -- "$plugin" $remove_plugins
+ for name in (string replace --filter --regex -- '.+/conf\.d/([^/]+)\.fish$' '$1' $$plugin_files_var)
+ emit {$name}_uninstall
+ end
+ printf "%s\n" Removing\ (set_color red --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~
+ set --erase _fisher_plugins[$index]
+ end
+
+ command rm -rf (string replace -- \~ ~ $$plugin_files_var)
+
+ functions --erase (string replace --filter --regex -- '.+/functions/([^/]+)\.fish$' '$1' $$plugin_files_var)
+
+ for name in (string replace --filter --regex -- '.+/completions/([^/]+)\.fish$' '$1' $$plugin_files_var)
+ complete --erase --command $name
+ end
+
+ set --erase $plugin_files_var
+ end
+ end
+
+ if set --query update_plugins[1] || set --query install_plugins[1]
+ command mkdir -p $fisher_path/{functions,themes,conf.d,completions}
+ end
+
+ for plugin in $update_plugins $install_plugins
+ set --local source $source_plugins[(contains --index -- "$plugin" $fetch_plugins)]
+ set --local files $source/{functions,themes,conf.d,completions}/*
+
+ if set --local index (contains --index -- $plugin $install_plugins)
+ set --local user_files $fisher_path/{functions,themes,conf.d,completions}/*
+ set --local conflict_files
+
+ for file in (string replace -- $source/ $fisher_path/ $files)
+ contains -- $file $user_files && set --append conflict_files $file
+ end
+
+ if set --query conflict_files[1] && set --erase install_plugins[$index]
+ echo -s "fisher: Cannot install \"$plugin\": please remove or move conflicting files first:" \n" "$conflict_files >&2
+ continue
+ end
+ end
+
+ for file in (string replace -- $source/ "" $files)
+ command cp -RLf $source/$file $fisher_path/$file
+ end
+
+ set --local plugin_files_var _fisher_(string escape --style=var -- $plugin)_files
+
+ set --query files[1] && set --universal $plugin_files_var (string replace -- $source $fisher_path $files | string replace -- ~ \~)
+
+ contains -- $plugin $_fisher_plugins || set --universal --append _fisher_plugins $plugin
+ contains -- $plugin $install_plugins && set --local event install || set --local event update
+
+ printf "%s\n" Installing\ (set_color --bold)$plugin(set_color normal) " "$$plugin_files_var | string replace -- \~ ~
+
+ for file in (string match --regex -- '.+/[^/]+\.fish$' $$plugin_files_var | string replace -- \~ ~)
+ source $file
+ if set --local name (string replace --regex -- '.+conf\.d/([^/]+)\.fish$' '$1' $file)
+ emit {$name}_$event
+ end
+ end
+ end
+
+ command rm -rf $source_plugins
+
+ if set --query _fisher_plugins[1]
+ set --local commit_plugins
+
+ for plugin in $file_plugins
+ contains -- (string lower -- $plugin) (string lower -- $_fisher_plugins) && set --append commit_plugins $plugin
+ end
+
+ for plugin in $_fisher_plugins
+ contains -- (string lower -- $plugin) (string lower -- $commit_plugins) || set --append commit_plugins $plugin
+ end
+
+ printf "%s\n" $commit_plugins >$fish_plugins
+ else
+ set --erase _fisher_plugins
+ command rm -f $fish_plugins
+ end
+
+ set --local total (count $install_plugins) (count $update_plugins) (count $remove_plugins)
+
+ test "$total" != "0 0 0" && echo (string join ", " (
+ test $total[1] = 0 || echo "Installed $total[1]") (
+ test $total[2] = 0 || echo "Updated $total[2]") (
+ test $total[3] = 0 || echo "Removed $total[3]")
+ ) plugin/s
+ case \*
+ echo "fisher: Unknown command: \"$cmd\"" >&2 && return 1
+ end
+end
+
+if ! set --query _fisher_upgraded_to_4_4
+ set --universal _fisher_upgraded_to_4_4
+ if functions --query _fisher_list
+ set --query XDG_DATA_HOME[1] || set --local XDG_DATA_HOME ~/.local/share
+ command rm -rf $XDG_DATA_HOME/fisher
+ functions --erase _fisher_{list,plugin_parse}
+ fisher update >/dev/null 2>/dev/null
+ else
+ for var in (set --names | string match --entire --regex '^_fisher_.+_files$')
+ set $var (string replace -- ~ \~ $$var)
+ end
+ functions --erase _fisher_fish_postexec
+ end
+end
diff --git a/.config/fish/functions/nvm.fish b/.config/fish/functions/nvm.fish
new file mode 100644
index 0000000..179dc45
--- /dev/null
+++ b/.config/fish/functions/nvm.fish
@@ -0,0 +1,234 @@
+function nvm --description "Node version manager"
+ for silent in --silent -s
+ if set --local index (contains --index -- $silent $argv)
+ set --erase argv[$index] && break
+ end
+ set --erase silent
+ end
+
+ set --local cmd $argv[1]
+ set --local ver $argv[2]
+
+ if set --query silent && ! set --query cmd[1]
+ echo "nvm: Version number not specified (see nvm -h for usage)" >&2
+ return 1
+ end
+
+ if ! set --query ver[1] && contains -- "$cmd" install use
+ for file in .nvmrc .node-version
+ set file (_nvm_find_up $PWD $file) && read ver <$file && break
+ end
+
+ if ! set --query ver[1]
+ echo "nvm: Invalid version or missing \".nvmrc\" file" >&2
+ return 1
+ end
+ end
+
+ set --local their_version $ver
+
+ switch "$cmd"
+ case -v --version
+ echo "nvm, version 2.2.13"
+ case "" -h --help
+ echo "Usage: nvm install <version> Download and activate the specified Node version"
+ echo " nvm install Install the version specified in the nearest .nvmrc file"
+ echo " nvm use <version> Activate the specified Node version in the current shell"
+ echo " nvm use Activate the version specified in the nearest .nvmrc file"
+ echo " nvm list List installed Node versions"
+ echo " nvm list-remote List available Node versions to install"
+ echo " nvm list-remote <regex> List Node versions matching a given regex pattern"
+ echo " nvm current Print the currently-active Node version"
+ echo " nvm uninstall <version> Uninstall the specified Node version"
+ echo "Options:"
+ echo " -s, --silent Suppress standard output"
+ echo " -v, --version Print the version of nvm"
+ echo " -h, --help Print this help message"
+ echo "Variables:"
+ echo " nvm_arch Override architecture, e.g. x64-musl"
+ echo " nvm_mirror Use a mirror for downloading Node binaries"
+ echo " nvm_default_version Set the default version for new shells"
+ echo " nvm_default_packages Install a list of packages every time a Node version is installed"
+ echo "Examples:"
+ echo " nvm install latest Install the latest version of Node"
+ echo " nvm use 14.15.1 Use Node version 14.15.1"
+ echo " nvm use system Activate the system's Node version"
+
+ case install
+ _nvm_index_update
+
+ string match --entire --regex -- (_nvm_version_match $ver) <$nvm_data/.index | read ver alias
+
+ if ! set --query ver[1]
+ echo "nvm: Invalid version number or alias: \"$their_version\"" >&2
+ return 1
+ end
+
+ if test ! -e $nvm_data/$ver
+ set --local os (command uname -s | string lower)
+ set --local ext tar.gz
+ set --local arch (command uname -m)
+
+ switch $os
+ case aix
+ set arch ppc64
+ case sunos
+ case linux
+ case darwin
+ case {MSYS_NT,MINGW\*_NT}\*
+ set os win
+ set ext zip
+ case \*
+ echo "nvm: Unsupported operating system: \"$os\"" >&2
+ return 1
+ end
+
+ switch $arch
+ case i\*86
+ set arch x86
+ case x86_64
+ set arch x64
+ case arm64
+ string match --regex --quiet "v(?<major>\d+)" $ver
+ if test "$os" = darwin -a $major -lt 16
+ set arch x64
+ end
+ case armv6 armv6l
+ set arch armv6l
+ case armv7 armv7l
+ set arch armv7l
+ case armv8 armv8l aarch64
+ set arch arm64
+ end
+
+ set --query nvm_arch && set arch $nvm_arch
+
+ set --local dir "node-$ver-$os-$arch"
+ set --local url $nvm_mirror/$ver/$dir.$ext
+
+ command mkdir -p $nvm_data/$ver
+
+ if ! set --query silent
+ echo -e "Installing Node \x1b[1m$ver\x1b[22m $alias"
+ echo -e "Fetching \x1b[4m$url\x1b[24m\x1b[7m"
+ end
+
+ if ! command curl $silent --progress-bar --location $url |
+ command tar --extract --gzip --directory $nvm_data/$ver 2>/dev/null
+ command rm -rf $nvm_data/$ver
+ echo -e "\033[F\33[2K\x1b[0mnvm: Invalid mirror or host unavailable: \"$url\"" >&2
+ return 1
+ end
+
+ set --query silent || echo -en "\033[F\33[2K\x1b[0m"
+
+ if test "$os" = win
+ command mv $nvm_data/$ver/$dir $nvm_data/$ver/bin
+ else
+ command mv $nvm_data/$ver/$dir/* $nvm_data/$ver
+ command rm -rf $nvm_data/$ver/$dir
+ end
+ end
+
+ if test $ver != "$nvm_current_version"
+ set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version
+ _nvm_version_activate $ver
+
+ set --query nvm_default_packages[1] && npm install --global $silent $nvm_default_packages
+ end
+
+ set --query silent || printf "Now using Node %s (npm %s) %s\n" (_nvm_node_info)
+ case use
+ test $ver = default && set ver $nvm_default_version
+ _nvm_list | string match --entire --regex -- (_nvm_version_match $ver) | read ver __
+
+ if ! set --query ver[1]
+ echo "nvm: Can't use Node \"$their_version\", version must be installed first" >&2
+ return 1
+ end
+
+ if test $ver != "$nvm_current_version"
+ set --query nvm_current_version && _nvm_version_deactivate $nvm_current_version
+ test $ver != system && _nvm_version_activate $ver
+ end
+
+ set --query silent || printf "Now using Node %s (npm %s) %s\n" (_nvm_node_info)
+ case uninstall
+ if test -z "$ver"
+ echo "nvm: Not enough arguments for command: \"$cmd\"" >&2
+ return 1
+ end
+
+ test $ver = default && test ! -z "$nvm_default_version" && set ver $nvm_default_version
+
+ _nvm_list | string match --entire --regex -- (_nvm_version_match $ver) | read ver __
+
+ if ! set -q ver[1]
+ echo "nvm: Node version not installed or invalid: \"$their_version\"" >&2
+ return 1
+ end
+
+ set --query silent || printf "Uninstalling Node %s %s\n" $ver (string replace ~ \~ "$nvm_data/$ver/bin/node")
+
+ _nvm_version_deactivate $ver
+
+ command rm -rf $nvm_data/$ver
+ case current
+ _nvm_current
+ case ls list
+ _nvm_list | _nvm_list_format (_nvm_current) $argv[2]
+ case lsr {ls,list}-remote
+ _nvm_index_update || return
+ _nvm_list | command awk '
+ FILENAME == "-" && (is_local[$1] = FNR == NR) { next } {
+ print $0 (is_local[$1] ? " ✓" : "")
+ }
+ ' - $nvm_data/.index | _nvm_list_format (_nvm_current) $argv[2]
+ case \*
+ echo "nvm: Unknown command or option: \"$cmd\" (see nvm -h for usage)" >&2
+ return 1
+ end
+end
+
+function _nvm_find_up --argument-names path file
+ test -e "$path/$file" && echo $path/$file || begin
+ test ! -z "$path" || return
+ _nvm_find_up (string replace --regex -- '/[^/]*$' "" $path) $file
+ end
+end
+
+function _nvm_version_match --argument-names ver
+ string replace --regex -- '^v?(\d+|\d+\.\d+)$' 'v$1.' $ver |
+ string replace --filter --regex -- '^v?(\d+)' 'v$1' |
+ string escape --style=regex || string lower '\b'$ver'(?:/\w+)?$'
+end
+
+function _nvm_list_format --argument-names current regex
+ command awk -v current="$current" -v regex="$regex" '
+ $0 ~ regex {
+ aliases[versions[i++] = $1] = $2 " " $3
+ pad = (n = length($1)) > pad ? n : pad
+ }
+ END {
+ if (!i) exit 1
+ while (i--)
+ printf((current == versions[i] ? " ▶ " : " ") "%"pad"s %s\n",
+ versions[i], aliases[versions[i]])
+ }
+ '
+end
+
+function _nvm_current
+ command --search --quiet node || return
+ set --query nvm_current_version && echo $nvm_current_version || echo system
+end
+
+function _nvm_node_info
+ set --local npm_path (string replace bin/npm-cli.js "" (realpath (command --search npm)))
+ test -f $npm_path/package.json || set --local npm_version_default (command npm --version)
+ command node --eval "
+ console.log(process.version)
+ console.log('$npm_version_default' ? '$npm_version_default': require('$npm_path/package.json').version)
+ console.log(process.execPath)
+ " | string replace -- ~ \~
+end