![如何让分支名称出现在 VS Code 集成终端中?](https://linux22.com/image/1628247/%E5%A6%82%E4%BD%95%E8%AE%A9%E5%88%86%E6%94%AF%E5%90%8D%E7%A7%B0%E5%87%BA%E7%8E%B0%E5%9C%A8%20VS%20Code%20%E9%9B%86%E6%88%90%E7%BB%88%E7%AB%AF%E4%B8%AD%EF%BC%9F.png)
我最近在 Mac 上安装了 VS Code 的新实例,集成终端不再显示当前分支。
在旧世界中,它会使用 git 显示我现在所在的分支,并在我更改分支时进行更新。
现在,它显示了我在文件目录中的位置,并且 git 正常工作,但它没有显示分支。
除了 GitHistory 之外,我没有其他扩展。以下是我的设置文件的摘录:
{
"workbench.statusBar.visible": false,
"explorer.decorations.colors": false,
"window.zoomLevel": 0,
"workbench.startupEditor": "newUntitledFile",
"workbench.editor.closeOnFileDelete": true,
"workbench.editor.limit.enabled": true,
"workbench.editor.openPositioning": "first",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"terminal.integrated.scrollback": 50000,
"terminal.integrated.shell.osx": ""
}
答案1
问题不在于 VS 代码,因为您实际上正在查看您的终端。
您只需编辑定义终端显示方式的设置。
如果您使用的是 MacOS Catalina,那么您可以编辑该 ~/.zshrc
文件。
这应该是您需要的代码-
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'\e[0m'
COLOR_USR=$'\e[38;5;243m'
COLOR_DIR=$'\e[38;5;197m'
COLOR_GIT=$'\e[38;5;39m'
NEWLINE=$'\n'
setopt PROMPT_SUBST
export PROMPT='${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}%% '