I make use of Windows Terminal a lot. It’s great for having multiple different pieces of work open at the same time.

Problem is, I’ve been forever getting lost, not knowing which tab is which. With every tab looking the same, going back to the right one always took a few seconds.

Fortunately, there’s a better way: a clever script that automatically sets the tab title to the name of the current directory whenever it encounters a .git folder:

Here’s the script. I have it saved in ~/.functions.sh and source it from my .bashrc file. (You could just embed it inline in .bashrc, but I like to make some effort to keep the size of that file down.)

#
# Wrapper for cd to proactively update Windows Terminal Tab titles with folder names when entering a git repo
#

cd() {
    # Call the builtin cd command
    builtin cd "$@"
    
    # Check if the new directory contains a .git folder
    if [ -d ".git" ]; then
        # Get the basename of the current directory
        local folder_name="${PWD##*/}"
        # Set the terminal tab title
        echo -ne "\\033]0;${folder_name}\\a"
    fi
}

Comments

blog comments powered by Disqus
Next Post
Superpowers for your AI  29 Mar 2026
Prior Post
Don't assume shared understanding  25 Jan 2026
Related Posts
Superpowers for your AI  29 Mar 2026
Don't assume shared understanding  25 Jan 2026
Better Table Tests in Go  21 Oct 2025
Error assertions  26 Apr 2025
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
Archives
March 2026
2026