[gnu.bash.bug] Bash example for xterm users

bothner@WSL.DEC.COM (09/09/89)

Xterm users may want to add something like the following to their
.bashrc. It sets the working directory and hostname in the title bar,
and writes the prompt with underlining.
Also, the function 'setname' changes the icon name, and the
prefix of the title bar.
Note that what may look like ^[ and ^G are <Escape> and <Bell>.
Brian, you are welcome to include this (or something similar)
in the examples directory.
	--Per

if [ "$PS1" ]; then

  # Set xterm "name" of terminal, and update icon name.
  function setname {
     TERMNAME="$*"
     if [ "$TERM" = "xterm" ]; then echo -n "]1;${TERMNAME}"; fi
  }

  if [ ! "$LOGIN_SHELL" ]; then
    if [ "$TERM" = "xterm" ]; then
      if [ ! "$TERMNAME" ]; then TERMNAME=xterm; fi
      # Set xterm title bar name.
      PS1=']2;${TERMNAME}: \w@\h[4m\h<\!>[0m'
    else
      PS1='\h:\w[\!] '
    fi
  fi

fi

bothner@wsl.dec.com (09/09/89)

Alas, the example I just sent out confuses bash too easily.
The problem is most likely that the length of the string
is longer than the actual visible prompt string.
So simple commands work fine, but (say) file-name completion
loses big.

In fact, I got the following output:
free: Called with already freed block argument

Tell bfox@ai.mit.edu to fix this someday.
Mailing a bug report...Freeze file out of date
--- and then I got the folling (bounced) mail message.
	--Per
P.S.
One solution is to have "normal" strings in PS1,
and then alias cd,pushd, etc to have the side effect of
changing the title bar. This works reasonably well in tcsh,
but I haven't tried it for bash.

It would also help if readline (?) could be made more robust.
This may be hard for arbitrary control sequences, but one
could have a convention that when calculating the length of
a prompt string, only count characters after a '\r' or '\n'.
Then one could place a '\r' after the "invisible" part of the prompt.

Another solution is to do something like tcsh's precmd alias,
which is automatically executed before each prompt.
The "precmd" could be responsible for setting the title bar.
------------------------
This is a Bash bug report.  Bash maintainers should be getting this report.
If this mail has bounced, for right now please send it to:

	bfox@ai.mit.edu

since he is the current maintainer of this version of the shell.

This is /usr/local/bin/bash (invoked as `/private/usr/local/emacs/info/bash'), version 1.03.109, on host wslt03.pa.dec.com, used by bothner.
This shell is interactive, and it is not a login shell.

The host is a SONY running Bsd.

The current environment is:
function setname () {
{ TERMNAME="$*"; if [ "$TERM" = "xterm" ] ; then
  echo -n "]1;${TERMNAME}"
fi
 }
}
TERMNAME=xterm
OLDPWD=/mnt/bothner
no_exit_on_failed_exec=
notify=
auto_resume=
function dc () {
{ echo "Oops! mistyped cd again, I assume!"; builtin cd $* }
}
function unsetenv () {
{ unset $* }
}
function setenv () {
{ export $1="$2" }
}
STANDARD_PATH=/usr/local/bin:/usr/bin/X11:/usr/sony/bin/X11:/etc:/usr/etc:/usr/ucb:/bin:/usr/bin:/usr/sony/bin:/usr/new:/usr/new/mh:/usr/pds/bin:/usr/hosts:/usr/sony/games:/usr/pds/games:/usr/games
UTIL_PATH=:/usr/bin/X11
MACH=vax
X11=/usr/bin/X11
GNU=
HOST=wslt03.pa.dec.com
EUID=7
UID=7
HISTSIZE=256
HISTFILE=/mnt/bothner/.bash_history
BASH_VERSION=1.03.109
PWD=/usr/local/emacs/info
MAILPATH=/usr/spool/mail/bothner
MAILCHECK=60
IFS= 	

PS2=bash>
PS1=]2;${TERMNAME}: \w@\h\r\h<\!>
MANPATH=/usr/local/man:/usr/man
cputype=mc68020
machine=news800
SYS_LANGUAGE=Japanese
TZ=pst8pdt
HOME=/mnt/bothner
SHELL=/usr/local/bin/bash
TERM=xterm
USER=bothner
PATH=/usr/local/bin:/usr/bin/X11:/usr/sony/bin/X11:/etc:/usr/etc:/usr/ucb:/bin:/usr/bin:/usr/sony/bin:/usr/new:/usr/new/mh:/usr/pds/bin:/usr/hosts:/usr/sony/games:/usr/pds/games:/usr/games:.
TTYPE=ascii
SHLVL=4
BASH=/usr/local/bin/bash
TERMCAP=vs|xterm|vs100|xterm terminal emulator (X window system):	:cr=^M:do=^J:nl=^J:bl=^G:le=^H:ho=\E[H:	:co#80:li#24:cl=\E[H\E[2J:bs:am:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:	:ce=\E[K:cd=\E[J:so=\E[7m:se=2\E[m:us=\E[4m:ue=\E[m:	:md=\E[1m:mr=\E[7m:me=2\E[m:	:ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:	:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:ta=^I:pt:sf=\n:sr=\EM:	:al=\E[L:dl=\E[M:ic=\E[@:dc=\E[P:	:MT:ks=\E[?1h\E=:ke=\E[?1l\E>:	:is=\E[r\E\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:	:rs=\E[r\E<\E[m\E[2J\E[H\E[?7h\E[?1;3;4;6l:xn:	:AL=\E[%

dL:DL=\E[%dM:IC=\E[%d@:DC=\E[%dP:	:ti=\E7\E[?47h:te=\E[2J\E[?47l\E8:	:as=\E(0:ae=\E(B:DE=^H:
WINDOWID=4194309
DISPLAY=unix:0.0

And here are the last 40 commands.

ls
cd src-g++/
ls
t HINTS 
t ChangeLog 
ls -l ideas
t ideas 
cd
uncompress gcc.xtar.Z 
cd /mnt/g++
cd /mnt/gnu/g++
ls
d src-g++/
cd src-g++/
ls 
cd /mnt/emacs
ls
ls /mnt/gnu
cd ..
cd emacs
cd /mnt/gnu/emacs
ls
cd dist-18.55/
ls
cd info/
ls
t dir
cd /usr/local/lib
ls
cd ../emacs
ls
cd info
pwd
ls
df
cd
ls
ls -l *.Z
rm et.tar.Z
rm imake

bfox@AUREL.CALTECH.EDU (Brian Fox) (09/10/89)

   Date: Fri, 08 Sep 89 19:35:42 -0700
   From: bothner@wsl.dec.com

   One solution is to have "normal" strings in PS1,
   and then alias cd,pushd, etc to have the side effect of
   changing the title bar. This works reasonably well in tcsh,
   but I haven't tried it for bash.

   It would also help if readline (?) could be made more robust.
   This may be hard for arbitrary control sequences, but one
   could have a convention that when calculating the length of
   a prompt string, only count characters after a '\r' or '\n'.
   Then one could place a '\r' after the "invisible" part of the prompt.

Yes, this should be done, but it will not solve the problem.  The
specific set of commands might be "esc-seq string esc-seq".  There is no
place in that string where a \r could be placed to tell bash where the
cursor was.


   Another solution is to do something like tcsh's precmd alias,
   which is automatically executed before each prompt.

You mean Bash's PROMPT_COMMAND variable?

   The "precmd" could be responsible for setting the title bar.

Brian