Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

5 Answers

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

share|improve this answer
2  
Has no effect for me :/ Maybe this trick has broken in the last 6 months? –  Mozza314 Mar 5 '13 at 23:36
    
Are you using bash? –  James Fu Mar 28 '13 at 7:40
1  
It has no effect when issued from within a screen. –  Ярослав Рахматуллин May 3 '13 at 6:29
add comment

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
add comment

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
add comment

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
add comment

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/connect.sh

The connect.sh 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.

connect.sh

#!/bin/bash

echo "Enter servername when prompted"
echo -n "servername: " 
read servername
function settitle() {
    echo -ne "\033]2;"$servername"\007"
}
function title() {
    settitle $(cygpath -m `pwd`)
}
settitle
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.