diff --git a/README.md b/README.md index 38771f0..2151f8c 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,10 @@ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`). +**Note:** If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there. + ```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 ``` diff --git a/install.sh b/install.sh index 7bf62df..2115f3f 100755 --- a/install.sh +++ b/install.sh @@ -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() { diff --git a/test/install_script/nvm_install_dir b/test/install_script/nvm_install_dir index 1aeea18..78da611 100755 --- a/test/install_script/nvm_install_dir +++ b/test/install_script/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