Merge 27432616ba into 812d6e4ab4
This commit is contained in:
commit
505371e9a0
54
install.sh
54
install.sh
|
|
@ -267,16 +267,54 @@ nvm_detect_profile() {
|
||||||
local DETECTED_PROFILE
|
local DETECTED_PROFILE
|
||||||
DETECTED_PROFILE=''
|
DETECTED_PROFILE=''
|
||||||
|
|
||||||
if [ -n "${BASH_VERSION-}" ]; then
|
# Detect the user's login shell
|
||||||
if [ -f "$HOME/.bashrc" ]; then
|
local USER_SHELL
|
||||||
DETECTED_PROFILE="$HOME/.bashrc"
|
local USER_SHELL_NAME
|
||||||
elif [ -f "$HOME/.bash_profile" ]; then
|
USER_SHELL=''
|
||||||
DETECTED_PROFILE="$HOME/.bash_profile"
|
|
||||||
fi
|
# If we're not testing, try to get shell from passwd
|
||||||
elif [ -n "${ZSH_VERSION-}" ]; then
|
# Otherwise, try the SHELL variable
|
||||||
DETECTED_PROFILE="$HOME/.zshrc"
|
if [ "$NVM_TESTING" != 'yes' ]; then
|
||||||
|
USER_SHELL=$(getent passwd $(whoami) | cut -d: -f7)
|
||||||
|
elif [ -n "$SHELL" ]; then
|
||||||
|
USER_SHELL="$SHELL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
USER_SHELL_NAME="${USER_SHELL##*/}"
|
||||||
|
|
||||||
|
# First try to find the config file based on the shell name
|
||||||
|
if [ -n "${USER_SHELL_NAME}" ]; then
|
||||||
|
case "${USER_SHELL_NAME}" in
|
||||||
|
bash)
|
||||||
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.bashrc"
|
||||||
|
elif [ -f "$HOME/.bash_profile" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.bash_profile"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
zsh)
|
||||||
|
if [ -f "$HOME/.zshrc" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.zshrc"
|
||||||
|
elif [ -f "$HOME/.zprofile" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.zprofile"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
ksh*)
|
||||||
|
if [ -f "$HOME/.kshrc" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.kshrc"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
mksh)
|
||||||
|
if [ -f "$HOME/.mkshrc" ]; then
|
||||||
|
DETECTED_PROFILE="$HOME/.mkshrc"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Now brute force
|
||||||
if [ -z "$DETECTED_PROFILE" ]; then
|
if [ -z "$DETECTED_PROFILE" ]; then
|
||||||
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
|
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc"
|
||||||
do
|
do
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
|
|
||||||
setup () {
|
setup () {
|
||||||
HOME="."
|
HOME="."
|
||||||
|
SHELL='/bin/bash'
|
||||||
NVM_ENV=testing \. ../../install.sh
|
NVM_ENV=testing \. ../../install.sh
|
||||||
|
NVM_TESTING='yes'
|
||||||
touch ".bashrc"
|
touch ".bashrc"
|
||||||
touch ".bash_profile"
|
touch ".bash_profile"
|
||||||
touch ".zshrc"
|
touch ".zshrc"
|
||||||
|
|
@ -12,6 +14,7 @@ setup () {
|
||||||
|
|
||||||
cleanup () {
|
cleanup () {
|
||||||
unset HOME
|
unset HOME
|
||||||
|
unset SHELL
|
||||||
unset NVM_ENV
|
unset NVM_ENV
|
||||||
unset NVM_DETECT_PROFILE
|
unset NVM_DETECT_PROFILE
|
||||||
unset BASH_VERSION
|
unset BASH_VERSION
|
||||||
|
|
@ -34,6 +37,12 @@ if [ -n "$NVM_DETECT_PROFILE" ]; then
|
||||||
die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null"
|
die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# .bashrc should be detected if the shell is bash
|
||||||
|
NVM_DETECT_PROFILE="$(unset PROFILE; nvm_detect_profile)"
|
||||||
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
|
||||||
|
die "nvm_detect_profile didn't pick \$HOME/.bashrc for bash"
|
||||||
|
fi
|
||||||
|
|
||||||
# .bashrc should be detected for bash
|
# .bashrc should be detected for bash
|
||||||
NVM_DETECT_PROFILE="$(BASH_VERSION="1"; unset PROFILE; nvm_detect_profile)"
|
NVM_DETECT_PROFILE="$(BASH_VERSION="1"; unset PROFILE; nvm_detect_profile)"
|
||||||
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
|
||||||
|
|
@ -46,8 +55,14 @@ if [ "$NVM_DETECT_PROFILE" != "test_profile" ]; then
|
||||||
die "nvm_detect_profile ignored \$PROFILE"
|
die "nvm_detect_profile ignored \$PROFILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# .zshrc should be detected if the shell is zsh
|
||||||
|
NVM_DETECT_PROFILE="$(SHELL="/bin/zsh"; unset PROFILE; unset BASH_VERSION; nvm_detect_profile)"
|
||||||
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
|
||||||
|
die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"
|
||||||
|
fi
|
||||||
|
|
||||||
# .zshrc should be detected for zsh
|
# .zshrc should be detected for zsh
|
||||||
NVM_DETECT_PROFILE="$(ZSH_VERSION="1"; unset PROFILE; unset BASH_VERSION; nvm_detect_profile)"
|
NVM_DETECT_PROFILE="$(SHELL="/bin/zsh"; ZSH_VERSION="1"; unset PROFILE; unset BASH_VERSION; nvm_detect_profile)"
|
||||||
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
|
||||||
die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"
|
die "nvm_detect_profile didn't pick \$HOME/.zshrc for zsh"
|
||||||
fi
|
fi
|
||||||
|
|
@ -82,7 +97,8 @@ fi
|
||||||
# return an empty value if everything fails
|
# return an empty value if everything fails
|
||||||
#
|
#
|
||||||
|
|
||||||
# It should favor .profile if file exists
|
# It should favor .profile if other detection methods fail and file exists and
|
||||||
|
SHELL="nonsense"
|
||||||
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; nvm_detect_profile)"
|
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; nvm_detect_profile)"
|
||||||
if [ "$NVM_DETECT_PROFILE" != "$HOME/.profile" ]; then
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.profile" ]; then
|
||||||
die "nvm_detect_profile should have selected .profile"
|
die "nvm_detect_profile should have selected .profile"
|
||||||
|
|
@ -104,7 +120,7 @@ fi
|
||||||
|
|
||||||
# Otherwise, it should favor .zshrc if file exists
|
# Otherwise, it should favor .zshrc if file exists
|
||||||
rm ".bash_profile"
|
rm ".bash_profile"
|
||||||
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; nvm_detect_profile)"
|
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; unset SHELL; nvm_detect_profile)"
|
||||||
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.zshrc" ]; then
|
||||||
die "nvm_detect_profile should have selected .zshrc"
|
die "nvm_detect_profile should have selected .zshrc"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
# Needed to avoid to checkout the repo to the latest nvm version, losing the commits of the current PR
|
# Needed to avoid to checkout the repo to the latest nvm version, losing the commits of the current PR
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue