How to change the title of the mintty window?

Solution 1:

What is wrong

The following command was not working for me:

echo -ne "\e]0;MYTITLE\a"

It turns out that my default Cygwin installation includes the following prompt definition in .bashrc:

PS1=\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$

Note that the first part of the prompt (\e]0;\w\a) is setting the windows title every time the prompt appears.

The solution

Add these lines in your .bashrc that define 2 functions:

function settitle() {
      export PS1="\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$ "
      echo -ne "\e]0;$1\a"
}
function settitlepath() {
      export PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n$ "
}

Then you can set a custom title with this command:

settitle "MYWonderfullTest here"

or you can revert to cygwin's default (the current path) with this command:

settitlepath

Hope this helps

Solution 2:

You can change it with the xterm control sequence for this, like so:

echo -ne '\e]0;Title\a'

Refer to: http://code.google.com/p/mintty/issues/detail?id=241

Solution 3:

Place this in .zshrc:

# Change title of MinTTY to current dir
function settitle() {
    echo -ne "\033]2;"$1"\007"
}
function chpwd() {
    settitle $(cygpath -m `pwd`)
}

The sequence of special characters in function settitle makes MinTTY change the title of the window.

In zsh, if you define a function with the special name chpwd, it will be invoked after each chdir.

Works on WinXP, with Cygwin 1.7 and MinTTY running zsh.

Solution 4:

In bash, the variable PROMPT_COMMAND can be set to hold a number of commands, seperated by semicolons. you can use that to do the same title setting as described in the other response that talks about zsh.

Solution 5:

1) echo $PS1 and copy that string to your clipboard or text editor, as in
   echo $PS1
2) edit ~/.bash_profile and add shell code below, replacing $PS1 as necessary but keep the ${TERMINAL_TITLE} variable in the "false" condition.
3) Save the file and set the TERMINAL_TILE environment variable, as in
   export TERMINAL_TITLE="My Custom Title"
4) Source your bash profile, as in
   . ~/.bash_profile
Enjoy

if [ -z "${TERMINAL_TITLE}" ]
then
  PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
else
  PS1='\[\e]0;${TERMINAL_TITLE}\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
fi