Merge pull request #765 from CristianCantoro/master
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Detect shell type from $SHELL variable instead of .$SHELLrc files
authored by Jordan Harband · committed by Jordan Harband · parents f81b6d6, c37dbbe · Browse files · 2 files·+79 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+79 added−23 removed
- tests:+47 added−13 removed
- other:+32 added−10 removed
Provenance
- Commit
1f679fc- Tree
7b0b36f- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
f81b6d6- Parent 2
c37dbbe
2 files changed+79 added−23 removed
modified:test/install_script/nvm_detect_profile+47 added-13 removed
20 unmodified lines21 HOME="."22 23 setup24 25+#Let's force $SHELL to be bash26+SHELL="/bin/bash"27 28+# $SHELL is set to bash and .bashrc is there, it must be detected29+_PROFILE=$(nvm_detect_profile)30+[ "_$_PROFILE" = "_$HOME/.bashrc" ] || echo "_\$HOME/.bashrc: _$HOME/.bashrc\n" \31+ echo "_\$_PROFILE: _$_PROFILE\n" \32+ die "nvm_detect_profile didn't pick $SHELL and $HOME/.bashrc"33+34+#Let's force $SHELL to be zsh35+SHELL="/usr/bin/zsh"36+37+# $SHELL is set to zsh and .zshrc is there, it must be detected38+_PROFILE=$(nvm_detect_profile)39+[ "_$_PROFILE" = "_$HOME/.zshrc" ] || echo "_\$HOME/.zshrc: _$HOME/.zshrc\n" \40+ echo "_\$_PROFILE: _$_PROFILE\n" \41+ die "nvm_detect_profile didn't pick $SHELL and $HOME/.zshrc"42+43+44+# if we unset shell it looks for the files45+unset SHELL46+47 # $PROFILE points to a valid file, its path must be returned48 PROFILE="test_profile"49 _PROFILE=$(nvm_detect_profile)29-[ "_$_PROFILE" = "_$PROFILE" ] || die "nvm_detect_profile didn't pick \$PROFILE"50+[ "_$_PROFILE" = "_$PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \51+ echo "_\$PROFILE: _$PROFILE\n" \52+ die "nvm_detect_profile didn't pick \$PROFILE"53 54 # $PROFILE doesn't point to a valid file, its path must not be returned55 PROFILE="invalid_profile"56 _PROFILE=$(nvm_detect_profile)34-[ "_$_PROFILE" != "_$PROFILE" ] || die "nvm_detect_profile shouldn't pick \$PROFILE when it's not a valid file"57+[ "_$_PROFILE" != "_$PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \58+ echo "_\$PROFILE: _$PROFILE\n" \59+ die "nvm_detect_profile shouldn't pick \$PROFILE when it's not a valid file"60 61 62 # Below are tests for when $PROFILE is undefined63 rm test_profile64 unset PROFILE65 41-# It should favor .bashrc if file exists66+# It should favor .profile if file exists67 _PROFILE=$(nvm_detect_profile)43-[ "_$_PROFILE" = "_$HOME/.bashrc" ] || die "nvm_detect_profile should have selected .bashrc"68+[ "_$_PROFILE" = "_$HOME/.profile" ] || echo "_\$_PROFILE: _$_PROFILE\n" \69+ echo "_\$PROFILE: _$PROFILE\n" \70+ die "nvm_detect_profile should have selected .profile"71 72+rm .profile73+# Otherwise, it should favor .bashrc if file exists74+_PROFILE=$(nvm_detect_profile)75+[ "_$_PROFILE" = "_$HOME/.bashrc" ] || echo "_\$_PROFILE: _$_PROFILE\n" \76+ echo "_\$PROFILE: _$PROFILE\n" \77+ die "nvm_detect_profile should have selected .bashrc"78+79 rm .bashrc80 # Otherwise, it should favor .bash_profile if file exists81 _PROFILE=$(nvm_detect_profile)48-[ "_$_PROFILE" = "_$HOME/.bash_profile" ] || die "nvm_detect_profile should have selected .bash_profile"82+[ "_$_PROFILE" = "_$HOME/.bash_profile" ] || echo "_\$_PROFILE: _$_PROFILE\n" \83+ echo "_\$PROFILE: _$PROFILE\n" \84+ die "nvm_detect_profile should have selected .bash_profile"85 86 rm .bash_profile87 # Otherwise, it should favor .zshrc if file exists88 _PROFILE=$(nvm_detect_profile)53-[ "_$_PROFILE" = "_$HOME/.zshrc" ] || die "nvm_detect_profile should have selected .zshrc"89+[ "_$_PROFILE" = "_$HOME/.zshrc" ] || echo "_\$_PROFILE: _$_PROFILE\n" \90+ echo "_\$PROFILE: _$PROFILE\n" \91+ die "nvm_detect_profile should have selected .zshrc"92 93 rm .zshrc56-# Otherwise, it should favor .profile if file exists57-_PROFILE=$(nvm_detect_profile)58-[ "_$_PROFILE" = "_$HOME/.profile" ] || die "nvm_detect_profile should have selected .profile"59-60-rm .profile94 # It should be empty if none is found95 _PROFILE=$(nvm_detect_profile)96+[ -z "$_PROFILE" ] || echo "_\$_PROFILE: _$_PROFILE\n" \97+ echo "_\$PROFILE: _$PROFILE\n" \63-[ -z "$_PROFILE" ] || die "nvm_detect_profile should have echo'ed an empty value"98+ die "nvm_detect_profile should have echo'ed an empty value"99 100 101 cleanup67-modified:install.sh+32 added-10 removed
115 unmodified lines116 # The echo'ed path is guaranteed to be an existing file117 # Otherwise, an empty string is returned118 #119 nvm_detect_profile() {120- if [ -f "$PROFILE" ]; then121- echo "$PROFILE"122- elif [ -f "$HOME/.bashrc" ]; then123- echo "$HOME/.bashrc"124- elif [ -f "$HOME/.bash_profile" ]; then125- echo "$HOME/.bash_profile"126- elif [ -f "$HOME/.zshrc" ]; then127- echo "$HOME/.zshrc"128- elif [ -f "$HOME/.profile" ]; then129- echo "$HOME/.profile"120+121+ local DETECTED_PROFILE122+ DETECTED_PROFILE=''123+ local SHELLTYPE124+ SHELLTYPE="$(basename /$SHELL)"125+126+ if [ $SHELLTYPE = "bash" ]; then127+ if [ -f "$HOME/.bashrc" ]; then128+ DETECTED_PROFILE="$HOME/.bashrc"129+ elif [ -f "$HOME/.bash_profile" ]; then130+ DETECTED_PROFILE="$HOME/.bash_profile"131+ fi132+ elif [ $SHELLTYPE = "zsh" ]; then133+ DETECTED_PROFILE="$HOME/.zshrc"134 fi135+136+ if [ -z $DETECTED_PROFILE ]; then137+ if [ -f "$PROFILE" ]; then138+ DETECTED_PROFILE="$PROFILE"139+ elif [ -f "$HOME/.profile" ]; then140+ DETECTED_PROFILE="$HOME/.profile"141+ elif [ -f "$HOME/.bashrc" ]; then142+ DETECTED_PROFILE="$HOME/.bashrc"143+ elif [ -f "$HOME/.bash_profile" ]; then144+ DETECTED_PROFILE="$HOME/.bash_profile"145+ elif [ -f "$HOME/.zshrc" ]; then146+ DETECTED_PROFILE="$HOME/.zshrc"147+ fi148+ fi149+150+ if [ ! -z $DETECTED_PROFILE ]; then151+ echo "$DETECTED_PROFILE"152+ fi153 }154 155 #156 # Check whether the user has any globally-installed npm modules in their system114 unmodified lines