Skip to content

Commit 211d88b

Browse files
[Fix] NVM_PROFILE bash/zsh detection in installation
1 parent fa22d71 commit 211d88b

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

install.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ nvm_latest_version() {
1414
echo "v0.33.1"
1515
}
1616

17+
nvm_profile_is_bash_or_zsh() {
18+
local TEST_PROFILE
19+
TEST_PROFILE="${1-}"
20+
case "${TEST_PROFILE-}" in
21+
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc")
22+
return
23+
;;
24+
*)
25+
return 1
26+
;;
27+
esac
28+
}
29+
1730
#
1831
# Outputs the location to NVM depending on:
1932
# * The availability of $NVM_SOURCE
@@ -305,11 +318,9 @@ nvm_do_install() {
305318
echo "=> Append the following lines to the correct file yourself:"
306319
command printf "${SOURCE_STR}"
307320
else
308-
case "${NVM_PROFILE-}" in
309-
".bashrc" | ".bash_profile" | ".zshrc")
310-
BASH_OR_ZSH=true
311-
;;
312-
esac
321+
if nvm_profile_is_bash_or_zsh "${NVM_PROFILE-}"; then
322+
BASH_OR_ZSH=true
323+
fi
313324
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
314325
echo "=> Appending nvm source string to $NVM_PROFILE"
315326
command printf "${SOURCE_STR}" >> "$NVM_PROFILE"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
3+
die () { echo "$@" ; exit 1; }
4+
5+
NVM_ENV=testing \. ../../install.sh
6+
7+
#nvm_profile_is_bash_or_zsh is available
8+
type nvm_profile_is_bash_or_zsh > /dev/null 2>&1 || die 'nvm_profile_is_bash_or_zsh is not available'
9+
nvm_profile_is_bash_or_zsh "/home/nvm/.bashrc" || die '/home/nvm/.bashrc is bash profile'
10+
nvm_profile_is_bash_or_zsh "/home/nvm/.bash_profile" || die '/home/nvm/.bash_profile is bash profile'
11+
nvm_profile_is_bash_or_zsh "/home/nvm/.zshrc" || die '/home/nvm/.zshrc is zsh profile'
12+
if nvm_profile_is_bash_or_zsh "/home/nvm/.bash"; then die '/home/nvm/.bash is not bash nor zsh profile'; fi
13+
if nvm_profile_is_bash_or_zsh "/home/nvm/.zsh" ; then die '/home/nvm/.zsh is not bash nor zsh profile'; fi

0 commit comments

Comments
 (0)