Skip to content
Myr

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

2 files+79 added−23 removed

modified:test/install_script/nvm_detect_profile+47 added-13 removed
20 unmodified lines
21HOME="."2223setup2425#Let's force $SHELL to be bash26SHELL="/bin/bash"2728# $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"3334#Let's force $SHELL to be zsh35SHELL="/usr/bin/zsh"3637# $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"424344# if we unset shell it looks for the files45unset SHELL4647# $PROFILE points to a valid file, its path must be returned48PROFILE="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"5354# $PROFILE doesn't point to a valid file, its path must not be returned55PROFILE="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"606162# Below are tests for when $PROFILE is undefined63rm test_profile64unset PROFILE6541# 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"7172rm .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"7879rm .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"8586rm .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"9293rm .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"5960rm .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"99100101cleanup67
modified:install.sh+32 added-10 removed
115 unmodified lines
116# The echo'ed path is guaranteed to be an existing file117# Otherwise, an empty string is returned118#119nvm_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"120121 local DETECTED_PROFILE122 DETECTED_PROFILE=''123 local SHELLTYPE124 SHELLTYPE="$(basename /$SHELL)"125126 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 fi135136 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 fi149150 if [ ! -z $DETECTED_PROFILE ]; then151 echo "$DETECTED_PROFILE"152 fi153}154155#156# Check whether the user has any globally-installed npm modules in their system
114 unmodified lines