Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

MinTTY is the new default Console for Cygwin.

What's a shell command (something I can put in .bashrc, or even better, in .zshrc) to change the title of the MinTTY window ?

I'd like the title of the window to be the path to the current directory, and to have it updated as I switch directories inside the console.

share|improve this question
Cygwin's default prompt setting (i.e. $PS1) already contains a control sequence that sets the window title to user@machine:working_directory. – ak2 Nov 29 '11 at 8:50
A recent MSYS2_packages/filesystem commit 6e6310d (filesystem: New specific variable MSYS2_PS1., 2016-05-01) introduced an MSYS2_PS1 prompt script, allowing distinct Cygwin/MSYS2 configurations. I've proposed a tweak to ensure that any existing PS1 has an intermediate priority Hope this helps. – Philip Oakley Jul 6 at 13:38
@Philip, (note from self) That tweak has proved contentious and further tweaks are being added (or removed) to create the minimum viable fix that covers the different usages. – Philip Oakley Jul 17 at 10:21

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

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

Refer to:

share|improve this answer
Has no effect for me :/ Maybe this trick has broken in the last 6 months? – voltrevo Mar 5 '13 at 23:36
Are you using bash? – James Fu Mar 28 '13 at 7:40
It has no effect when issued from within a screen. – Ярослав Рахматуллин May 3 '13 at 6:29
Probably the problem is that the command prompt is already configured to update the title (for exmaple with the current path), so the command works but it is suddenly overridden by the prompt. – Andrea Polci Jul 28 '14 at 7:47

After reading some answers to this question, I was unable to quickly understand why my terminal title stay unchanged.

The following command line is no sufficient

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

You will need to check that other environment variables doesn't include this kind of directive. For example, with a default Cygwin installation, you could have the following prompt definition:

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

As you can see the first part of the prompt is defining the windows title:


What I've done to change this behavior is to keep by default the original PS1 value, and provide a way to set a custom title. You could add the following in you .bashrc:

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$ "

This way, you could retrieve the path in the windows title :


or set a custom string :

settitle "MYWonderfullTest here"

Hope this helps

share|improve this answer
Great job, addressing the PS1 problem that most users will run into with default cygwin settings. – Markku K. Jan 27 at 19:13
This should have been accepted as the answer as it works perfectly unlike the highest voted answer – Tapan Chandra Jul 14 at 14:40
I love an answer I can just cut and paste. And also clearly explains what the problem really is. – Darrel Lee Jul 19 at 10:29

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.

share|improve this answer
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

if [ -z "${TERMINAL_TITLE}" ]
  PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
  PS1='\[\e]0;${TERMINAL_TITLE}\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
share|improve this answer

I used Leonel's answer, but I found the title would only flicker when doing this, which means at least the echo command works as intended. I ran zsh interactively with debug mode enabled using

zsh -xv

Changing the directory evidently invokes another function called title() after precmd() and chpwd(), effectively overriding them. So I plugged this into my .zshrc and it worked.

function settitle() {
    echo -ne "\033]2;"$1"\007"
function title() {
    settitle $(cygpath -m `pwd`)

If you prefer to use chpwd() or precmd() instead, simply disable the title function: title(){}.

share|improve this answer

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.

share|improve this answer

Just wanted to share my solution to this as I use mintty to execute a script.

My mintty shortcut is setup as:

C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico /usr/bin/bash.exe -l -c /scripts/

The script that I wrote which is called in the shortcut above will prompt me for the server I want to connect to AND execute the settitle function defined in the script.


echo "Enter servername when prompted"
echo -n "servername: " 
read servername
function settitle() {
    echo -ne "\033]2;"$servername"\007"
function title() {
    settitle $(cygpath -m `pwd`)
ssh my_username@$servername
share|improve this answer
Why do you define the function title if you do not use it? – pabouk Nov 12 '13 at 0:18

try add this into .bash_profile

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD/#$HOME/~}\007"'

It works for me.

share|improve this answer
The question is about changing the window title, not a command prompt. – kenorb Jul 28 '15 at 10:08
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – DavidPostill Jul 28 '15 at 10:50
please add this into .bash_profile, it is OK for change title, thanks! – netawater Jul 28 '15 at 14:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .