Setting Dynamic Tab Titles in Windows Terminal

Thursday, 06 July 2023
Powershell Windows Terminal
Edit This Page

Setting Dynamic Tab Titles in Windows Terminal

Windows Terminal is a powerful tool that brings the command line back to the modern age. It supports tabs, which is a great feature for multitasking. However, keeping track of what each tab is doing can be a challenge. This is where dynamic tab titles come in handy.

In this post, we'll show you how to set dynamic tab titles in Windows Terminal using PowerShell. This will allow you to quickly identify what each tab is doing, enhancing your productivity.

The PowerShell Function

We'll start by creating a PowerShell function that sets the window title to the name of the current Git repository or the current directory if it's not in a Git repository.

Here's the function:

function Set-Title() {
    $repo = git rev-parse --show-toplevel 2>$null
    if ($LASTEXITCODE -eq 0) {
        $repo = Split-Path -Leaf $repo
    } else {
        $repo = Split-Path -Leaf (Get-Location)
    }
    $host.UI.RawUI.WindowTitle = $repo
}

This function first tries to get the root directory of the current Git repository. If it's not in a Git repository, it sets the window title to the name of the current directory.

Using the Function

To use this function, you just need to call Set-Title in your PowerShell session. This will immediately update the window title.

You can also add this function to your PowerShell profile so that it's available every time you open a new PowerShell session. To do this, open your PowerShell profile in a text editor and add the function at the end.

Conclusion

With this simple PowerShell function, you can make your Windows Terminal tabs much more informative. Whether you're working in a Git repository or just navigating directories, you'll always know where you are.

So go ahead, turn your LIQUID code SOLID, and let your coding superpowers shine. Remember, every great coder is just a superhero in disguise. Stay frosty, coders!