How to add a title to xterm

Robert Body rbody99@hotmail.com
Wed Dec 7 17:02:00 GMT 2005


Here is a script that works in bash or ksh for setting the title based on 
your current path, by setting up $PS1. I have also seen similar thing done 
by aliasing "cd" command

I use bash mostly, but for ksh there is need for Perl in my script below to 
accomplish the passing of ESC characters to ksh. I could not figure out how 
to do it with awk
-Robert

case "`echo "_$0" | /usr/bin/tr '[:upper:]' '[:lower:]' | sed -e 's/^_//'`" 
in
#############################################################################
bash     | -bash     | */bash )
#############################################################################
echo "...running bash"
    HOSTNAME=`hostname`; export HOSTNAME     # Set a HOSTNAME variable
#----------------------------------------------------------------------------
# 29=white,30=black,31=red,32=green,33=yellow, 34=blue,35=magenta,36=cyan
#----------------------------------------------------------------------------
    # Set a default prompt of: user@host and current_directory
#    PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
#    PS1='\[\e]0;$HOSTNAME: $PWD\a\]\[\e[36m\]$PWD>\[\e[0m\] '        # (in 
title) HOST-$PWD ... $PATH
    PS1='\[\e]0;$ME: $PWD\a\]$PWD> '        # (in title) HOST-$PWD ... $PATH
;;
#############################################################################
ksh*     | -ksh*     | */ksh* )
#############################################################################
echo "...running ksh"
    typeset -l HOSTNAME           # Set a HOSTNAME variable

    PS1=$(perl -e 'printf"\033]0;$ARGV[0]: \$PWD\007\033[29m\$PWD>\033[0m\ 
"' $ME)
;;
esac



>From: "Ehud Karni" <ehud@unix.mvs.co.il>
>Reply-To: cygwin-xfree@cygwin.com
>To: fergus@bonhard.uklinux.net
>CC: cygwin-xfree@cygwin.com
>Subject: Re: How to add a title to xterm
>Date: Wed, 7 Dec 2005 18:43:29 +0200
>
>On Wed, 7 Dec 2005 06:54:41 -0000, fergus <fergus@bonhard.uklinux.net> 
>wrote:
> >
> > > How to add a title to xterm?
> >
> > I do not use startx: for me, it sets up unnecessary or inconvenient
> > defaults.
>
>You can always set the xterm title by sending it the string: Esc ] 0 ;
><your title> ^G . You can do it from the xterm application (writing to
>/dev/tty or stdout if its connected, or externally, by writing to
>/dev/tty<n> [Cygwin] or /dev/pts/<n> [Linux]).
>
>Bellow is a small script that update the title if it is run on an
>interactive xterm (the 2nd is a tty emulator written here).
>
>Ehud
>
>
>#! /bin/sh -e
># this script sets the TTY title to 1st argument
># --------------------------------------------------
>
>if [ -t 1 ] ; then                             # do only if stdout is 
>terminal
>     TTL=`echo "$1" | sed -e "s/ [ ]*/ /g"`     # any length of spaces to 1 
>space
>     case "$TERM" in
>         xter* ) echo "\033]0;$TTL\a\c"         # write it to xterm window 
>title
>                 ;;
>         npc* )  DTTL=`echo "$TTL\c" | od -An -tu1 -v | tr "\012" " " | sed 
>-e "s/ [ ]*/;/g"`
>                 echo "\033[=/${DTTL:1:999};253;t\c"    # For Mivtach Simon 
>TTY
>                 ;;
>     esac
>fi
>
>############################## set_tty_title ##############################
>
>
>--
>  Ehud Karni           Tel: +972-3-7966-561  /"\
>  Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
>  Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
>  http://www.mvs.co.il  FAX:  1-815-5509341  / \
>  GnuPG: 98EA398D <http://www.keyserver.net/>    Better Safe Than Sorry
>
>--
>Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>Problem reports:       http://cygwin.com/problems.html
>Documentation:         http://x.cygwin.com/docs/
>FAQ:                   http://x.cygwin.com/docs/faq/
>



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/



More information about the Cygwin-xfree mailing list