[New] add support for `$XDG_CONFIG_HOME`

Erik Lilja 2018-08-14 21:45:40 +02:00 committed by Jordan Harband
parent f218a85454
commit 8542df4ac5
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
3 changed files with 13 additions and 4 deletions

View File

@ -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
``` ```

View File

@ -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() {

View File

@ -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