Per default cygwin sets the PS1 variable so that the window title always shows the current directory. However, if you use telnet/ssh to login to a different computer, the title isn’t changed. If you tend to have several windows open (like myself), you end up with a lot of cygwin windows with unmeaningful names.
This morning I finally decided to do something about it, and wrote quick wrapper scripts for telnet. The script should be fairly self-explanatory:
#!/bin/sh
#
# Wrapper script to set window title to the host contacted.
#
# Helper function to set title of window
function settitle() { echo -ne “\e]2;$@\a\e]1;$@\a”; }
#
# Default cygwin PS1 also sets the title, effectively overriding any custom settings.
# We therefore set PS1 to zero, and restore it afterwards.
#
PS1_BCKUP=$PS1
PS1=
# Make sure PS1 is restored even in case of interrupts
trap “PS1=$PS1_BCKUP” 0
trap “exit 2″ 1 2 3 15
settitle $1
/usr/bin/telnet $1
June 4, 2008 at 6:56 pm |
Hi,
Here’s what I use to set both the title and the prompt to provide the full information. If you have this PS1 setting on the destination machine, it will continue to give up-to-date user/host/path information as you change directories on the destination machine.
# Use this version to restrict user@host and path to title only.
#PS1=’\[\e]0;\u@\h \w\a\]\n\$’
# Use this version for user@host and path in both title and prompt
PS1=’\[\e]0;\u@\h \w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$’
August 24, 2008 at 11:13 am |
I got ./.SetCygwinTitle.sh[8]: Syntax error at line 8 : `(‘ is not expected.
thx.
February 18, 2010 at 1:05 pm |
remember you may have to source the script to make it apply to your /current/ shell