The problem
Since macOS Catalina and later Apple has changed the default shell terminal to zsh. Most of your scripts based on bash will have incompatibility issues with zsh. You can switch to bash but the version that comes with macOS is pretty old. Let’s change that.
Assumptions
- You are on a mac device running macOS 10.15 and later.
Install brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install the latest Bash and make it your default login shell
# install latest bash
brew install bash
# install newer bash completions
brew install bash-completion@2
# Add /usr/local/bin/bash to the list of allowed login shells
echo /usr/local/bin/bash | sudo tee -a /etc/shells
# Change the default shell for your Mac terminal
chsh -s /usr/local/bin/bash
# Change the login shell for your user
sudo chpass -s /usr/local/bin/bash your_username
Append to your ~/.bash_profile
# Git functions
git_branch() {
git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# Terminal prompt
PS1="\[\e[0;93m\]\u\[\e[m\]@" # username
PS1+="\[\e[0;92m\]\h\[\e[m\]" # hostname
PS1+=" " # space
PS1+="\[\e[0;95m\]\W\[\e[m\]" # current directory
PS1+="\[\e[0;92m\]\$(git_branch)\[\e[m\]" # current branch
PS1+=" " # space
PS1+="$ " # end prompt
export PS1
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export PATH="$HOME/bin:/usr/local/bin:/usr/local/opt/python/libexec/bin:$HOME/.local/bin:$PATH"
# Bash v5 completions
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
# Get rid of Apple's Bash deprecation warning
export BASH_SILENCE_DEPRECATION_WARNING=1
