【git/VSC】在VSC的terminal中显示git分支名

3,756 阅读1分钟

1.在Mac OS(catalina)中,VSC默认整合是的shell是zsh。我们需要去到VSC的user setting配置文件中,增加以下一条配置:

2.修改bash的配置文件

$ cd ~
$ vi ./.bash_profile

把以下的内容粘贴进入:

# Git branch in prompt.

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

最后执行一下命令让配置生效:

$ source ./.bash_profile

3.关闭并重启VSC,打开terminal。就能看到shell已经切换为bash,并且目录名后面会显示git分支名:

参考资料