Adding git branch on the Bash command prompt

前端 未结 13 2092
感情败类
感情败类 2020-11-30 16:15

I tried adding the git branch I\'m currently working on (checked-out) on the bash prompt without success.. (while keeping my current path which shows the active dir

13条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-30 17:16

    root:~/project#  -> root:~/project(dev)# 
    

    add the following code to the end of your ~/.bashrc

    force_color_prompt=yes
    color_prompt=yes
    parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    }
    if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
    else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
    fi
    unset color_prompt force_color_prompt
    

提交回复
热议问题