Setting Cygwin's window title
I use Cygwin at work to give me access to the many irreplaceable Unix tools. It works extraordinarily well. Unfortunately, it is still a Windows application and therefore carries many of the unproductive traits of the rest of the Windows software world. In particular, once a few different Cygwin windows are open, the Windows task bar becomes littered with indistinguishable Cygwin entries.
I wrote this simple shell script to easily allow a title to be set for individual Cygwin windows, which is also reflected in the task bar for easy identification when searching for a particular window. Be wary that if your title does not stick, your PS1 variable may be overriding the title each time the prompt is displayed.
#!/bin/shecho -e "\033]2;$1 $2 $3 $4 $5 $6\007"
If this is named settitle.sh for example, and made executable, it may be invoked like this:
settitle.sh Work
or
settitle.sh Waveform data analysis
with up to 6 words in the title. The extra spaces that result from defaulting to allowing 6 words in the title do not seem to cause enough trouble to warrant doing anything about them. It would be simple to check for the number of arguments if you wish to modify the script, and you could easily allow for more words (or just group them by quotes) if you so desire.
Comments
Thanks! You saved me some time trying to find these special escape characters again. However, you can just create a function to do this:
function .t()
{
echo -e "\033]2;$*\007"
}
It's just as powerful, and quicker to type. :-)
Posted by: William | January 13, 2009 1:36 AM
Actually, the default .bashrc has this function already in it (though commented-out):
function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; }
Posted by: David | June 26, 2009 6:56 AM
Thanks for the post, though. Wouldn't have thought about bash functions to do this without it. :)
Posted by: David | June 26, 2009 7:26 AM
Instead of $1 $2 $3 $4 $5 $6, you can just use $* which evaluates to all of the arguments given to the script.
Posted by: Alex | August 6, 2009 6:14 AM
Thanx for the great tip!
I hard-coded in the system name into the escape codes
since the script is a mouse target on my win-desktop:
echo -e "\033]2;Some-System-Name\007"
Posted by: Anonymous | January 14, 2010 10:43 PM