Setting the cygwin title for telnet/ssh

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

Advertisement

3 Responses to “Setting the cygwin title for telnet/ssh”

  1. Tony Garland Says:

    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\$’

  2. Rick Huang Says:

    I got ./.SetCygwinTitle.sh[8]: Syntax error at line 8 : `(‘ is not expected.

    thx.

  3. anders Says:

    remember you may have to source the script to make it apply to your /current/ shell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.