[Fix] install.sh: only write $HOME when $NVM_DIR is inside it
The profile line was built by replacing a leading `$HOME` with `sed`, without a path boundary, and with `$HOME` treated as a regex. With `HOME=/home/me` and `NVM_DIR=/home/me2/nvm`, or with `HOME=/` and `NVM_DIR=/usr/local/nvm`, the profile got `export NVM_DIR="$HOME2/nvm"` or `export NVM_DIR="$HOMEusr/local/nvm"`, which expand to the wrong directory, so nvm does not load in new shells. A `.` in `$HOME` matched any character, a `:` in it broke the `sed` expression, and a trailing slash on it left `$HOME.nvm`. Match `$HOME` literally, as a whole path component, and leave the path absolute when `$HOME` is empty.
This commit is contained in:
1 parent
93da6595ce
commit
c7a1b344da
2 files changed
+72
-1
No files matched your search
+7
-1
@@ -495,7 +495,13 @@ nvm_do_install() {
|
||||
local NVM_PROFILE
|
||||
NVM_PROFILE="$(nvm_detect_profile)"
|
||||
local PROFILE_INSTALL_DIR
|
||||
PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")"
|
||||
PROFILE_INSTALL_DIR="$(nvm_install_dir)"
|
||||
# an empty `$HOME` would make every absolute path look like it is inside it
|
||||
if [ -n "${HOME-}" ]; then
|
||||
case "${PROFILE_INSTALL_DIR}/" in
|
||||
"${HOME}"/*) PROFILE_INSTALL_DIR="\$HOME${PROFILE_INSTALL_DIR#"${HOME}"}" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n"
|
||||
|
||||
|
||||
Reference in new issue
Block a user