The existence of .bashrc, .bash_profile or .zshrc doesn't prove that the file is the currently utilized startup file or that it is the only file sourced. Because the current code operates under this assumption, the code:
```bash
export NVM_DIR="/Users/<USERNAME>/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
```
is getting appended to the wrong profile for zsh users.
1) `[ -d ~/.nvm ] && rm -rfv ~/.nvm `
2) Install Zsh via https://github.com/robbyrussell/oh-my-zsh
3) Run nvm install script with cURL.
4) Run `which nvm`. Observe it's not in `$PATH`
5) Open a new shell session. Observe the issue persists.
To fix this, the code in this PR checks:
- Is `$PROFILE` set? If so, echo it.
- What is the active shell that is executing this script? (the parent shell)
- If the shell is zsh, echo the zshrc file
- If the shell is bash:
- Is it login or non-login? Echo the neccessary file
- Is it interactive or non interactive? Echo the neccessary
file.
This logic should address the primary bug and also prevent future bugs.
Note: bash by default reads ~/.profile last so it makes sense to write to ~/.bashrc or ~/.bash_profile instead of ~/.profile
See: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
Passed Manual Tests:
✅ zsh
✅ bash from within script
✅ bash as default shell
✅ bash -l from within zsh
After a fresh install I was unable to run the installer again. It was breaking with the error
error: branch 'master' not found.
my fix makes sure that the installer continues after that.