Browse Source

[New] add support for `$XDG_CONFIG_HOME`

Erik Lilja 7 years ago committed by Jordan Harband
parent
commit
8542df4ac5
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
  1. 4
      README.md
  2. 8
      install.sh
  3. 5
      test/install_script/nvm_install_dir

4
README.md

@ -54,8 +54,10 @@ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | @@ -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>**Note:** If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there.</sub>
```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
```

8
install.sh

@ -7,7 +7,13 @@ nvm_has() { @@ -7,7 +7,13 @@ nvm_has() {
}
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() {

5
test/install_script/nvm_install_dir

@ -16,9 +16,10 @@ install_dir=$(nvm_install_dir) @@ -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"
unset NVM_DIR
# NVM_DIR is not set
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

Loading…
Cancel
Save