How can I display the current branch and folder path in terminal?

前端 未结 13 1141
无人共我
无人共我 2020-12-04 07:09

I\'ve been watching some of the Team Treehouse videos and they have a very nice looking terminal when working with Git.

For example they have (something similar):

13条回答
  •  心在旅途
    2020-12-04 07:44

    From Mac OS Catalina .bash_profile is replaced with .zprofile

    Step 1: Create a .zprofile

    touch .zprofile
    

    Step 2:

    nano .zprofile
    

    type below line in this

    source ~/.bash_profile
    

    and save(ctrl+o return ctrl+x)

    Step 3: Restart your terminal

    To Add Git Branch Name Now you can add below lines in .bash_profile

        parse_git_branch() {
        git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
    }
    
    export PS1="\u@\h \[\033[32m\]\w - \$(parse_git_branch)\[\033[00m\] $ "
    

    Restart your terminal this will work.

    Note: Even you can rename .bash_profile to .zprofile that also works.

提交回复
热议问题