mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-11-22 09:01:28 +03:00
`\cd` only bypasses aliases, so a user-defined `cd` function (eg, cdhist's) still ran, and broke `NVM_DIR` auto-detection when it rejected zsh's `-q`. Use `command cd`, which skips functions in POSIX shells. zsh's `command` runs `/usr/bin/cd` instead of the builtin, so use `builtin cd` there, as `nvm_echo` does for `printf`. `nvm_die_on_prefix` also now uses `nvm_cd` instead of a bare `cd`. Fixes #3835. See #3836. Co-authored-by: Elan Ruusamäe <glen@delfi.ee>
24 lines
579 B
Bash
Executable File
24 lines
579 B
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
EXPECTED="$(\cd .. && pwd)"
|
|
|
|
# a user-defined `cd` function that rejects nvm's arguments, like cdhist's (#3835)
|
|
cd() {
|
|
echo 'user-defined cd function was called' >&2
|
|
return 1
|
|
}
|
|
|
|
OUTPUT="$(nvm_cd .. 2>&1 && pwd)"
|
|
[ "${OUTPUT}" = "${EXPECTED}" ] || die "expected '${EXPECTED}', got '${OUTPUT}'"
|
|
|
|
# shellcheck disable=SC2086
|
|
OUTPUT="$(nvm_cd ${NVM_CD_FLAGS} .. 2>&1 && pwd)"
|
|
[ "${OUTPUT}" = "${EXPECTED}" ] || die "with NVM_CD_FLAGS '${NVM_CD_FLAGS}', expected '${EXPECTED}', got '${OUTPUT}'"
|
|
|
|
unset -f cd
|