
我最近在 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 code,因為您實際上正在查看終端。
您只需編輯定義終端顯示方式的設定即可。
如果您使用的是 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}%% '