gitvisual-studio-codegit-worktree

Show Git worktree name in VSCode's title bar


So I've recently started using git worktrees and they are magical.

But when using with Visual Studio Code, you will have the current branch name shown on the top (my_branch), so when you've opened more than 1 project (in my case I have 4 different projects interacting with each other) with the same branch name, you would get confused and have to browse the files to know which project you've opened.

is there a way I can show 2 levels of folder names, like my_project.git/my_branch?


Solution

  • The window title of Visual Studio Code can be edited as follows:

    1. Open settings.json, in either workspace or user scope
    2. Add "window.title": "${rootPath}${separator}${activeEditorMedium}" and save the file. This will result in a rather long title, but AFAIK there is no pretty way to get just the parent folder's name into the title.

    Available variables in the title are (copied from VSCode):

    Window: Title
    Controls the window title based on the active editor. Variables are substituted based on the context:
    
    ${activeEditorShort}: the file name (e.g. myFile.txt).
    ${activeEditorMedium}: the path of the file relative to the workspace folder (e.g. myFolder/myFileFolder/myFile.txt).
    ${activeEditorLong}: the full path of the file (e.g. /Users/Development/myFolder/myFileFolder/myFile.txt).
    ${activeFolderShort}: the name of the folder the file is contained in (e.g. myFileFolder).
    ${activeFolderMedium}: the path of the folder the file is contained in, relative to the workspace folder (e.g. myFolder/myFileFolder).
    ${activeFolderLong}: the full path of the folder the file is contained in (e.g. /Users/Development/myFolder/myFileFolder).
    ${folderName}: name of the workspace folder the file is contained in (e.g. myFolder).
    ${folderPath}: file path of the workspace folder the file is contained in (e.g. /Users/Development/myFolder).
    ${rootName}: name of the opened workspace or folder (e.g. myFolder or myWorkspace).
    ${rootPath}: file path of the opened workspace or folder (e.g. /Users/Development/myWorkspace).
    ${appName}: e.g. VS Code.
    ${remoteName}: e.g. SSH
    ${dirty}: an indicator for when the active editor has unsaved changes.
    ${separator}: a conditional separator (" - ") that only shows when surrounded by variables with values or static text.