mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-05-10 22:31:51 +00:00
Better shell detection, and better test handling
This commit is contained in:
parent
3cdedc97d8
commit
9ffd330f59
47
install.sh
47
install.sh
@ -234,24 +234,55 @@ nvm_detect_profile() {
|
|||||||
DETECTED_PROFILE=''
|
DETECTED_PROFILE=''
|
||||||
|
|
||||||
# Detect the user's login shell
|
# Detect the user's login shell
|
||||||
local DETECTED_SHELL
|
local USER_SHELL
|
||||||
local SHELLRC
|
local USER_SHELL_NAME
|
||||||
|
USER_SHELL=''
|
||||||
|
|
||||||
DETECTED_SHELL="${SHELL##*/}"
|
# If we're not testing, try to get shell from passwd
|
||||||
SHELLRC="$HOME/.${DETECTED_SHELL}rc"
|
# Otherwise, try the SHELL variable
|
||||||
|
if [ "$NVM_TESTING" != 'yes' ]; then
|
||||||
|
USER_SHELL=$(getent passwd $(whoami) | cut -d: -f7)
|
||||||
|
elif [ -n "$SHELL" ]; then
|
||||||
|
USER_SHELL="$SHELL"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "${DETECTED_SHELL}" ] && [ -f "$SHELLRC" ]; then
|
if [ -n "$SHELL" ]; then
|
||||||
DETECTED_PROFILE="$SHELLRC"
|
USER_SHELL_NAME="${USER_SHELL##*/}"
|
||||||
elif [ -n "${BASH_VERSION-}" ]; then
|
fi
|
||||||
|
|
||||||
|
# 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
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.bashrc"
|
DETECTED_PROFILE="$HOME/.bashrc"
|
||||||
elif [ -f "$HOME/.bash_profile" ]; then
|
elif [ -f "$HOME/.bash_profile" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.bash_profile"
|
DETECTED_PROFILE="$HOME/.bash_profile"
|
||||||
fi
|
fi
|
||||||
elif [ -n "${ZSH_VERSION-}" ]; then
|
;;
|
||||||
|
zsh)
|
||||||
|
if [ -f "$HOME/.zshrc" ]; then
|
||||||
DETECTED_PROFILE="$HOME/.zshrc"
|
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
|
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
|
||||||
|
@ -4,6 +4,7 @@ setup () {
|
|||||||
HOME="."
|
HOME="."
|
||||||
SHELL='/bin/bash'
|
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"
|
||||||
@ -97,21 +98,22 @@ fi
|
|||||||
#
|
#
|
||||||
|
|
||||||
# It should favor .profile if other detection methods fail and file exists and
|
# It should favor .profile if other detection methods fail and file exists and
|
||||||
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; unset SHELL; nvm_detect_profile)"
|
SHELL="nonsense"
|
||||||
|
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"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Otherwise, it should favor .bashrc if file exists
|
# Otherwise, it should favor .bashrc if file exists
|
||||||
rm ".profile"
|
rm ".profile"
|
||||||
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; unset SHELL; nvm_detect_profile)"
|
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; nvm_detect_profile)"
|
||||||
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then
|
||||||
die "nvm_detect_profile should have selected .bashrc"
|
die "nvm_detect_profile should have selected .bashrc"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Otherwise, it should favor .bash_profile if file exists
|
# Otherwise, it should favor .bash_profile if file exists
|
||||||
rm ".bashrc"
|
rm ".bashrc"
|
||||||
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; unset SHELL; nvm_detect_profile)"
|
NVM_DETECT_PROFILE="$(unset BASH_VERSION; unset ZSH_VERSION; nvm_detect_profile)"
|
||||||
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
|
if [ "$NVM_DETECT_PROFILE" != "$HOME/.bash_profile" ]; then
|
||||||
die "nvm_detect_profile should have selected .bash_profile"
|
die "nvm_detect_profile should have selected .bash_profile"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user