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