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
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 https://github.com/Alexpux/MSYS2-packages/pull/651. Hope this helps.
– Philip Oakley – 2016-07-06T13:38:18.793@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 – 2016-07-17T10:21:10.780
1
Related, if you only need a static title like "Cygwin i686" or "Cygwin x86_64", then you can use
– jww – 2016-10-14T07:26:47.783-T <title>
in the Windows shortcut properties. Also see themintty man page
.1Cygwin's default prompt setting (i.e.
$PS1
) already contains a control sequence that sets the window title to user@machine:working_directory. – ak2 – 2011-11-29T08:50:19.443