I tend to have a large number of terminal windows open, which can get a bit confusing - most of them are completely different projects, but with the folder named “app”, they can be hard to tell apart. Today I finally got around to customizing my bash prompt to solve the problem.
I found several scripts online to display the git branch in the prompt, but I wanted to take that a bit further and identify the open project as well. If origin has a url format similar to those used by GitHub or Bitbucket, this script will display the repo name together with the branch and path.
Add the below code to ~/.bash_profile to update your prompt:
export PS1="\n\e[0;37m\$(git remote -v 2>/dev/null | grep -e '^origin.*(fetch)' | sed 's/^.*\/\(.*\)\.git.*/\1:/')\$(git branch 2>/dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/') \w\e[00m \n\$ "