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
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
Solution 5
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.
Related videos on Youtube
Leonel
Updated on September 18, 2022Comments
-
Leonel over 1 year
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.
-
eylon shabtay over 12 yearsCygwin's default prompt setting (i.e.
$PS1
) already contains a control sequence that sets the window title to user@machine:working_directory. -
Philip Oakley almost 8 yearsA 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 github.com/Alexpux/MSYS2-packages/pull/651. Hope this helps.
-
Philip Oakley almost 8 years@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.
-
jww over 7 yearsRelated, if you only need a static title like "Cygwin i686" or "Cygwin x86_64", then you can use
-T <title>
in the Windows shortcut properties. Also see themintty man page
.
-
-
voltrevo over 11 yearsHas no effect for me :/ Maybe this trick has broken in the last 6 months?
-
James Fu about 11 yearsAre you using bash?
-
Ярослав Рахматуллин about 11 yearsIt has no effect when issued from within a screen.
-
pabouk - Ukraine stay strong over 10 yearsWhy do you define the function
title
if you do not use it? -
Andrea Polci almost 10 yearsProbably 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.
-
kenorb almost 9 yearsThe question is about changing the window title, not a command prompt.
-
netawater almost 9 yearsplease add this into .bash_profile, it is OK for change title, thanks!
-
Markku K. over 8 yearsGreat job, addressing the PS1 problem that most users will run into with default cygwin settings.
-
Tapan Chandra almost 8 yearsThis should have been accepted as the answer as it works perfectly unlike the highest voted answer
-
Darrel Lee almost 8 yearsI love an answer I can just cut and paste. And also clearly explains what the problem really is.
-
Curtis Yallop about 7 yearsTo test it "echo -ne '\e]0;Title\a' && cat". This method prevents the prompt from immediately resetting it. (If that works, you can alter PS1 in your profile as described in other answers)
-
Curtis Yallop about 7 yearsAlternate test: "echo -ne '\e]0;Title\a' && env -i bash --noprofile --norc".
-
hanshenrik almost 7 yearsthose functions works fine for me! remember that for cygwin to reload your .bashrc, you'll have to restart cygwin, OR write
source ~/.bashrc
- else cygwin will still be running the old version of bashrc that was on-disk when cygwin was started. - tested onCygwin version 2.8.1 (64 bit)
- a 2017 version -
zzxyz over 6 yearsAlso works in WSL (minus the cygpath stuff, of course):
settitle "$(pwd)@$HOST"
-
AJ Smith 'Smugger' over 6 yearsWhy was this answer never accepted?
-
jdhao over 5 yearsIf I ssh to my Linux server, the window title will change. How do I fix the window title after I start cygwin?
-
Peter Moore almost 4 years@kenorb This does affect the window title. in fact without setting PROMPT_COMMAND to blank you would not be able to change the window title with
echo -ne "\e]0;test\a"
because PROMPT_COMMAND would just revert it to user@host -
Peter Moore almost 4 years@asmith I dont think that this is an answer. Im not sure why it got so many votes. without setting
PROMPT_COMMAND
to blank these functions will have no effect for mintty because PROMPT_COMMAND overwrites the title on its default value on linux. The answer isexport PROMPT_COMMAND='echo -ne "\e]0;My desired title\a"'
orexport COMMAND_PROMPT=''
and then set it withecho -ne "\e]0;test\a"
regardless of whatPS1
is set to. -
Jordan Gee over 2 yearsSuggesting an improvement to add
(\$?)
, right before the\u@\h
(note the space) This gives you the exit status of the last line and it helps me sometimes.