-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix]
use
: Prepend instead of changing if shadowed by system dirs (f…
…ixes #1652)
- Loading branch information
Showing
2 changed files
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -638,12 +638,19 @@ nvm_change_path() { | |
elif ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/[^/]*${2-}" \ | ||
&& ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then | ||
nvm_echo "${3-}${2-}:${1-}" | ||
# if the initial path contains BOTH an nvm path (checked for above) and | ||
# that nvm path is preceded by a system binary path, just prepend the | ||
# supplementary path instead of replacing it. | ||
# https://github.com/creationix/nvm/issues/1652#issuecomment-342571223 | ||
elif nvm_echo "${1-}" | nvm_grep -Eq "(^|:)(/usr(/local)?)?${2-}:.*${NVM_DIR}/[^/]*${2-}" \ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ljharb
Member
|
||
|| nvm_echo "${1-}" | nvm_grep -Eq "(^|:)(/usr(/local)?)?${2-}:.*${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then | ||
nvm_echo "${3-}${2-}:${1-}" | ||
# use sed to replace the existing nvm path with the supplementary path. This | ||
# preserves the order of the path. | ||
else | ||
nvm_echo "${1-}" | command sed \ | ||
-e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#g" \ | ||
-e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#g" | ||
-e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#" \ | ||
-e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#" | ||
fi | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What about
~/.npm-packages/bin
? Is there any reason to replace existing path in place instead of always removing it and prepending? The latter would be consistent, would not require additional ifs like this and would work in more cases...