-
-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix] install
: detect user shell and try shellrc file first
#2260
base: master
Are you sure you want to change the base?
Changes from all commits
b2a4377
d01b62b
78933af
3cdedc9
9ffd330
2743261
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -233,16 +233,54 @@ nvm_detect_profile() { | |||||
local DETECTED_PROFILE | ||||||
DETECTED_PROFILE='' | ||||||
|
||||||
if [ -n "${BASH_VERSION-}" ]; then | ||||||
if [ -f "$HOME/.bashrc" ]; then | ||||||
DETECTED_PROFILE="$HOME/.bashrc" | ||||||
elif [ -f "$HOME/.bash_profile" ]; then | ||||||
DETECTED_PROFILE="$HOME/.bash_profile" | ||||||
fi | ||||||
elif [ -n "${ZSH_VERSION-}" ]; then | ||||||
DETECTED_PROFILE="$HOME/.zshrc" | ||||||
# Detect the user's login shell | ||||||
local USER_SHELL | ||||||
local USER_SHELL_NAME | ||||||
USER_SHELL='' | ||||||
|
||||||
# If we're not testing, try to get shell from passwd | ||||||
# Otherwise, try the SHELL variable | ||||||
if [ "$NVM_TESTING" != 'yes' ]; then | ||||||
USER_SHELL=$(getent passwd $(whoami) | cut -d: -f7) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shoot yeah I meant to see if getent exists on Mac, apparently it doesn't :/ Back to the drawing board! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So looking at it, there doesn't seem to be a standard POSIX way to do this -- and the current behavior of checking various shell versions certainly isn't POSIX, as there is no $DASH_VERSION for example. As such, I propose we do this: getent is the most reliable way on Linux machines, and it's quite standard. We could go one step further and just On MacOS, I think the best we can do is hope the $SHELL variable is accurate because Apple. MacOS apparently does its own thing for storing user info, so we could either write in logic to use
What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with trying a bunch of different things in the install script, as long as they fail gracefully on systems where they don't work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it! So Furthermore, if you decide to start a new |
||||||
elif [ -n "$SHELL" ]; then | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
USER_SHELL="$SHELL" | ||||||
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 | ||||||
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zshrc" | ||||||
do | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.