On Wed, Dec 27, 2000 at 12:55:19AM +0200, Nadav Har'El wrote:
> On Tue, Dec 26, 2000, Adi Stav wrote about "Re: spaces in filenames":
> > Speaking of, by the way, I wonder why almost everybody I've seen who
> > digs smart xterm titles uses the cd trick instead of something like:
> > 
> > PS1_SIMPLE="\h: \w "
> > PS1="\[\033]0;${PS1_SIMPLE}\007\]${PS1_SIMPLE}"
> 
> Maybe because your solution (at first glance - I didn't try it) changes the
> title on every prompt? This is a waste of bandwidth (though you won't notice
> it unless you have a slow line - e.g., log in to a computer abroad, or
> use a slow modem, or worse - a slow X connection). In some window managers it
> may also cause the title to flash on every prompt (though if it does, it's a
> bug that needs to be corrected in the window manager).
> 
> Anyway, your solution isn't bad - it's just that there's a more efficient
> solution: to only change the title when it needs changing, i.e., when the
> current directory has changed.

Ah, no. We are talking about five bytes here (plus the length of the
title). And since it will arrive through telnet (or equivalent)
together with the rest of the prompt, in normal use it will occupy a
very small single packet that has to be sent anyway, if only for the
newline. So there will generally be no latency problem even with very
slow modems.

I don't like the cd aliasing solution because it feels kludgy: what it
the cwd changes not because of cd (like choo pointed out)? What if you
want to display data other than your cwd in the title? Anyhow, if
efficiency is an principal thing, I suggest caching:

CURRENT_TITLE=""
retitle() {
        OLD_TITLE="$CURRENT_TITLE"
        CURRENT_TITLE="$*"
        [ "$CURRENT_TITLE" != "$OLD_TITLE" ] && \
                echo -n "\033]2;${CURRENT_TITLE}\007"
}
export PS1='\[`retitle whatever`\]whatever'

Warning: I haven't checked this one, don't have X at the moment.

> By the way, in zsh there's an even more elegant solution (if anybody got
> the impression that I'm an avid zsh advocate, they are right): zsh's
> standard 'cd' builtin runs a user-define function 'chpwd' after changing
> the directory, if such a function exists. So all you need to do is to
> add something like the following to your .zshrc (no need for 'cd' functions
> or aliases):
> 
> chpwd(){
>         case "$TERM" in
>         xterm|screen)   print -n '\033]2;'"$LOGNAME@$SYS":$PWD'\007';;
>         esac
> }
> chpwd   # run this once in the .zshrc to show the initial current directory

Did you manage to get it working with screen? Screen ate my control
characters when I tried it...


- Adi Stav

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to