[New] add support for `$XDG_CONFIG_HOME`
parent
f218a85454
commit
8542df4ac5
|
@ -54,8 +54,10 @@ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh |
|
||||||
|
|
||||||
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).</sub>
|
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).</sub>
|
||||||
|
|
||||||
|
<sub>**Note:** If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,13 @@ nvm_has() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_install_dir() {
|
nvm_install_dir() {
|
||||||
command printf %s "${NVM_DIR:-"$HOME/.nvm"}"
|
if [ ! -z "$NVM_DIR" ]; then
|
||||||
|
printf %s "${NVM_DIR}"
|
||||||
|
elif [ ! -z "$XDG_CONFIG_HOME" ]; then
|
||||||
|
printf %s "${XDG_CONFIG_HOME/nvm}"
|
||||||
|
else
|
||||||
|
printf %s "$HOME/.nvm"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_latest_version() {
|
nvm_latest_version() {
|
||||||
|
|
|
@ -16,9 +16,10 @@ install_dir=$(nvm_install_dir)
|
||||||
[ "_$install_dir" = "_$NVM_DIR" ] || die "nvm_install_dir should use \$NVM_DIR if it exists. Current output: $install_dir"
|
[ "_$install_dir" = "_$NVM_DIR" ] || die "nvm_install_dir should use \$NVM_DIR if it exists. Current output: $install_dir"
|
||||||
|
|
||||||
unset NVM_DIR
|
unset NVM_DIR
|
||||||
|
|
||||||
# NVM_DIR is not set
|
# NVM_DIR is not set
|
||||||
install_dir=$(nvm_install_dir)
|
install_dir=$(nvm_install_dir)
|
||||||
[ "_$install_dir" = "_$HOME/.nvm" ] || die "nvm_install_dir should default to \$HOME/.nvm. Current output: $install_dir"
|
fallback_dir=""
|
||||||
|
[ ! -z "$XDG_CONFIG_HOME" ] && fallback_dir="$XDG_CONFIG_HOME/nvm" || fallback_dir="$HOME/.nvm"
|
||||||
|
[ "_$install_dir" = "_$fallback_dir" ] || die "nvm_install_dir should default to \$XDG_CONFIG_DIR/.nvm. Current output: $install_dir"
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
Loading…
Reference in New Issue