TransWikia.com

How to get branch names to appear in the VS Code integrated terminal?

Super User Asked on November 4, 2021

I recently installed a new instance of VS Code on my Mac and the integrated terminal no longer shows the current branch.

In the old world, it would show which branch I was on right now with git and update as I changed branches.

Now, it shows my location in the file directory and git works as normal but it doesn’t show the branch.

I have no extensions except for GitHistory. This is an excerpt from my settings file:

{
    "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": ""
}

One Answer

The problem is not VS code because you're actually looking at your terminal.

You simply have to edit the settings that define how your terminal appears.

If you're on MacOS Catalina, then you can edit the ~/.zshrc file.

This should be the code that you need-

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}%% '

Answered by Cauder on November 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP