Note: OH-my-ZSH needs to be installed in order to use the following scheme normally. The installation method is not described here

Go to the root directory

cd ~
Copy the code

The editor.bashrcFile (automatically created if it is not present)

vim .bashrc
Copy the code

Add the following code to the end of the file

function git_branch { branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`" if [ "${branch}" != "" ]; then if [ "${branch}" = "(no branch)" ]; then branch="(`git rev-parse --short HEAD`...) " fi echo " ($branch)" fi } export PS1='\u@\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ 'Copy the code

Save the exit

According to the first

esc
Copy the code

Then,

:wq
Copy the code

Reload command

source ./.bashrc
Copy the code

The shell that launches under the Mac is login shell, so the configuration file loaded is.bash_profile, not.bashrc. For a Mac, you need to run the following command to make it automatically take effect after each startup:

echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
Copy the code

Finally finish the renderings