[comp.windows.x] changing titles

niermann@grumpy.csg.uiuc.edu (Tom Niermann) (02/12/90)

Is there a way to change the name displayed in the title bar from the command
line ? 

This could be done in sunwindows and was useful for displaying the current
directory and machine logged into by aliasing rlogin and cd.

Thanks
Tom

niermann@bach.csg.uiuc.edu

samlb@pioneer.arc.nasa.gov (Sam Bassett RCD) (02/12/90)

	Yes!

	Send <Esc>T<Title Text><LF> to the screen -- the <Title Text> can
be anything you want, event the output from `pwd`.

	echo "<Esc>T`pwd`" should do it handily.


Sam'l Bassett, Sterling Software @ NASA Ames Research Center, 
Moffett Field CA 94035 Work: (415) 694-4792;  Home: (415) 969-2644
samlb@well.sf.ca.us                     samlb@ames.arc.nasa.gov 
<Disclaimer> := 'Sterling doesn't _have_ opinions -- much less NASA!'

rcb@ccpv1.ncsu.edu (Randy Buckland) (02/12/90)

The only thing I've found that works in xterm is:

	<esc>]2;<text>^G

That's a control/g on the end.
Randy Buckland
rcb@ncsuvx.ncsu.edu

jc@minya.UUCP (John Chambers) (02/13/90)

In article <4869@amelia.nas.nasa.gov>, samlb@pioneer.arc.nasa.gov (Sam Bassett RCD) writes:
> 
> 	Send <Esc>T<Title Text><LF> to the screen -- the <Title Text> can
> be anything you want, event the output from `pwd`.
> 
> 	echo "<Esc>T`pwd`" should do it handily.

This doesn't work at all here (twm+xterm); it just puts the `pwd` minus
its first two bytes out on the next line, and doesn't alter the title
bar.  Here's what I use here and on some DECwindows systems at work:

switch ( "$TERM" )  # Some terminal-specific stuff.
	case xterm*:    # For xterm, we know how to write to the title bar.
			alias   setttl 'echo "^[]0;"$HOST":"`pwd`"^G"'
			alias   putttl 'echo "^[]0;"\!*"^G"'
	...

I then use setttl in the alias for cd and rlogin, and putttl when I want
to write the title bar from a script.

So how many different ways are there to do it, and on which systems?  Is
there any really portable way?


-- 
John Chambers ...!{harvard,ima,mit-eddie}!minya!jc

[Sorry, no clever saying today.]

chuck@Morgan.COM (Chuck Ocheret) (02/14/90)

Here is some Korn Shell code in my .envfile which sets up my prompt
to set the title to hostname followed by cwd; easily converted for
other shells.

	PS1="$(hostname) "'${PWD}'
	if [[ $(whoami) = root ]]
	then PEND='!#'
	else PEND='!$'
	fi
	if [[ ${TERM} = xterm ]]
	then PS1="];${PS1}${PEND}"
	else PS1="${PS1} ${PEND}"
	fi

The only problem with this is that my console window no longer says CONSOLE.
Does anyone know (under SUNOS) how to determine if a window is currently
the console window?

~chuck

-- 
 +------------------+   Chuck Ocheret, Sr. Staff Engineer   +-----------------+
 | chuck@Morgan.COM |       Morgan Stanley & Co., Inc.      | (212) 703-4474  |
 |   Duty now ...   |19th Floor, 1251 Avenue of the Americas| for the future. |
 +------------------+       New York, N.Y.  10020 USA       +-----------------+

bannon@betelgeuse.csc.ti.com (Tom Bannon) (02/14/90)

In article <NIERMANN.90Feb11143721@grumpy.csg.uiuc.edu> niermann@grumpy.csg.uiuc.edu (Tom Niermann) writes:

>   Is there a way to change the name displayed in the title bar from the command
>   line ? 

>   This could be done in sunwindows and was useful for displaying the current
>   directory and machine logged into by aliasing rlogin and cd.



I got this off the net awhile ago (comp.windows.x, from graham@fuel.dec.com 
(kris graham)) and modified it a bit to suit my tastes.  By aliasing certain 
commands you can get your current working directory in your xterm title bars, 
which I find very nice.  I have the lines below sitting in my .cshrc.  The 
"^[ is really "ESC[ and the "^G" is "control-G".  You can get the current 
directory string more than one way, see the pwd man page if you are interested.
You will get funny results if the machine you are logging into does not have 
the hostname program, which I use to set the variable HOST; there may be better
ways to get the host name than this.  With the []2 these escape sequences only 
affect the title bar on the xterm window, specify []0 if you would like it to 
affect the icon name as well.  BTW, this topic is beginning to look like a 
candidate for the "Common Questions & Answers" bin.

Enjoy,
Tom

bannon@csc.ti.com
Computer Science Center
Texas Instruments, Dallas

----------


    # Put machine and current directory in xterm title bar
    setenv HOST `hostname`
    if ($?DISPLAY) then
      echo -n "]2;"${HOST}":"`pwd`""
    endif

    # Alias to set the title freely
    alias title 'echo -n "]2;"\!*"" '

    # Alias cd, pushd, popd to update the title bar with dir and host
    alias cd 'cd \!*; echo -n "]2;"${HOST}":"`pwd`"" '
    alias pushd 'pushd \!*; echo -n "]2;"${HOST}":"`pwd`"" '
    alias popd 'popd \!*; echo -n "]2;"${HOST}":"`pwd`"" '
    alias rlogin 'echo -n "]2;"\!*":";/usr/ucb/rlogin \!*; echo -n "]2;"${HOST}":"`pwd`"" '

keane@ultima.cs.uts.oz (Chris Keane) (02/14/90)

In article <NIERMANN.90Feb11143721@grumpy.csg.uiuc.edu>, niermann@grumpy.csg.uiuc.edu (Tom Niermann) writes:
> Is there a way to change the name displayed in the title bar from the command
> line ? 
> 
sure, echo <ESC>]2;new-window-name<BEL>

where of course <ESC> is the escape character and <BEL> rings the bell
(normally control-g). I have a cd alias set up like this:

alias cd 'cd \!* ; echo ^[]2\;$HOSTNAME\:$cwd^G'

which changes my window title to where ever I am, eg zeus:/system/usr/keane

strobilatingly yours...
                                          Chris.
+-------------------------------------------------+
| The ultimate profit-making juke-box: It plays   |  keane@ultima.cs.uts.oz
| Kylie Minogue songs until you put money in it...|  Beam me up Scotty.
+-------------------------------------------------+
Disclaimer: These are my own opinions, but I'm insane. What's your excuse?

battlewr@BATTLE.ESD.ORNL.GOV (David L. Battle) (02/14/90)

Chris Keane writes:

> alias cd 'cd \!* ; echo ^[]2\;$HOSTNAME\:$cwd^G'
>
> which changes my window title to where ever I am, eg zeus:/system/usr/keane

Neat.  The only problem is that after you come back from an su, rlogin,
telnet, etc. session the title bar isn't updated.

I got a bit carried away and wanted to have the user name in the
title bar too since I have several user id's under which I do different
tasks.

Here's what I'm currently using (in my .cshrc):

setenv HOSTNAME `hostname`
setenv USERNAME `whoami`
alias tup 'echo -n ^[]2\;${USERNAME}@${HOSTNAME}:$cwd^G'
alias cd 'cd \!* ; tup'
alias telnet 'telnet \!* ; tup'
alias rlogin 'rlogin \!* ; tup'
alias dlogin 'dlogin \!* ; tup'
alias su 'su \!* ; tup'
tup

The "tup" at the end updates the title bar at login.

I didn't want to use the $USER variable because, at least under ultrix, when
one su's to root, $USER is still the user name you originally logged in under.


					-David L. Battle
					 battle@battle.esd.ornl.gov

casey@gauss.llnl.gov (Casey Leedom) (02/15/90)

| From: battlewr@BATTLE.ESD.ORNL.GOV (David L. Battle)
| 
| Chris Keane writes:
| 
| > alias cd 'cd \!* ; echo ^[]2\;$HOSTNAME\:$cwd^G'
| >
| > which changes my window title to where ever I am, eg zeus:/system/usr/keane
| 
| Neat.  The only problem is that after you come back from an su, rlogin,
| telnet, etc. session the title bar isn't updated.

  And David's solution is full of special cases.  Why don't you just put
the window title control string in you prompt and be done with it?  That
way you leave it to your shell to decide which prompt to display and when
to display it.  Try something like:

	alias	cd	'cd \!*; setprompt'
	alias	pushd	'pushd \!*; setprompt'
	alias	popd	'popd \!*; setprompt'
	alias	setprompt 'set prompt = "^[]2;$HOSTNAME\:$cwd^G% "'

(Actually my setprompt does a lot more than this, but you get the idea.)

Casey

chuck@Morgan.COM (Chuck Ocheret) (02/15/90)

>  ...And David's solution is full of special cases.  Why don't you just put
>  the window title control string in you prompt and be done with it? ...

I recently posted how to set up the ksh prompt to update the window title.
However, I have discovered a problem with this that I hope someone can help
me with.  The size of the prompt string seen by ksh includes the entire
escape sequence.  Since I include ${CWD} in the title string, the string
can get very long.  How do I prevent ksh from thinking I only have a few
characters positions left on my command line?  Ksh starts shifting the
line over when it thinks you are out of room.

~chuck
-- 
 +------------------+   Chuck Ocheret, Sr. Staff Engineer   +-----------------+
 | chuck@Morgan.COM |       Morgan Stanley & Co., Inc.      | (212) 703-4474  |
 |   Duty now ...   |19th Floor, 1251 Avenue of the Americas| for the future. |
 +------------------+       New York, N.Y.  10020 USA       +-----------------+

graham@fuel.dec.com (kris graham) (02/17/90)

In article <BANNON.90Feb13134554@betelgeuse.csc.ti.com>,
bannon@betelgeuse.csc.ti.com (Tom Bannon) writes:

> In article <NIERMANN.90Feb11143721@grumpy.csg.uiuc.edu>
niermann@grumpy.csg.uiuc.edu (Tom Niermann) writes:
> 
> >   Is there a way to change the name displayed in the title bar from
the command
> >   line ? 
> 
> >   This could be done in sunwindows and was useful for displaying the
current
> >   directory and machine logged into by aliasing rlogin and cd.
> 
> I got this off the net awhile ago (comp.windows.x, from graham@fuel.dec.com 
> (kris graham)) and modified it a bit to suit my tastes.  By aliasing certain 
> commands you can get your current working directory in your xterm
title bars, 
> which I find very nice.  

Here is another example that shows how to customize DECwindows
dxterms (a more powerful terminal emulator than xterm) and xterms,
plus, not losing your titles when you go in and out of rlogin, decnet, 
su, etc...

BTW:This was tested on ULTRIX  systems with .cshrc and X11.

  #
if (! $?0) then
  # we've been run from a login session
  echo running .cshrc
  # my favorite aliases here .....
  #........
  #............
 if ($?TERM) then
    if ($TERM == xterm) then
      stty dec pass8
      echo "initializing xterm"
      setenv HOSTNAME `hostname`
      echo -n "]0;"${HOSTNAME}"::"${cwd}""
      alias title 'echo -n "]0;"\!*"" '
      alias cd 'cd \!*; echo -n "]0;"${HOSTNAME}"::"${cwd}"" '
      alias pushd 'pushd \!*; echo -n "]0;"${HOSTNAME}"::"${cwd}"" '
      alias popd 'popd \!*; echo -n "]0;"${HOSTNAME}"::"${cwd}"" '
      alias rlogin 'echo -n "]0;"\!*"::";/usr/ucb/rlogin \!*; echo -n
"]0;"${HOSTNAME}"::"${cwd}"" '
      alias dlogin 'echo -n "]0;"\!*"::";/usr/bin/dlogin \!*; echo -n
"]0;"${HOSTNAME}"::"${cwd}"" '
    endif
    if ($TERM == 'vt200') then
      stty dec
      echo "initializing DECterm"
      setenv HOSTNAME `hostname`
      /usr/new/wtitle "${HOSTNAME}::${cwd}"
      alias title 'wtitle "${HOSTNAME}::$cwd" `tty`'
      alias cd 'cd \!*; wtitle "${HOSTNAME}::${cwd}" "${HOSTNAME}::${USER}"'
      alias pushd 'pushd \!*; wtitle "${HOSTNAME}::${cwd}"'
      alias popd 'popd \!*; wtitle "${HOSTNAME}::${cwd}"'
      alias rlogin 'wtitle \!*"::";/usr/ucb/rlogin \!*; wtitle
"${HOSTNAME}::${cwd}"'
      alias dlogin 'wtitle \!*"::";/usr/bin/dlogin \!*; wtitle
"${HOSTNAME}::${cwd}"'
      title
    endif
  endif
endif

------------------
Christopher Graham          
Digital Equipment Corp            
Ultrix Resource Center                                             
New York City

Internet: graham@fuel.enet.dec.com 
UUCP:     ...!decwrl!fuel.enet.dec.com!graham