----- Original Message ----- From: "fREW" <frioux@xxxxxxxxx>
To: "Mikael Magnusson" <mikachu@xxxxxxxxx> Cc: "Zsh users list" <zsh-users@xxxxxxxxxx> Sent: Thursday, May 24, 2007 2:51 PM Subject: Re: If then Prompt
On 5/24/07, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:On 24/05/07, fREW <frioux@xxxxxxxxx> wrote: > On 5/24/07, Mikael Magnusson <mikachu@xxxxxxxxx> wrote: > > On 24/05/07, fREW <frioux@xxxxxxxxx> wrote: > > > Hey all, > > > > > > I was thinking that it would be cool to show the number of jobs if> > > there were more than 0 jobs. I know you can do this with things > > > like> > > the return value, is there any way to do it with jobs? > > > > Sure, > > PS1=$'%(1j.%j jobs .)' > > > > -- > > Mikael Magnusson > > > > Awesome! Thanks! If anyone cares or wants to see it, here is my > current prompt. [...] > if [[ $TERM == linux ]]; then > else > precmd () { print -Pn "\e]0;%m: %~\a" } > fi > > > It doesn't show the username, because it usually doesn't matter to me > what user I am logged into (it's just a user or root) so I don't show > that. Also the last part which will put the current directory in the > title of an xterm doesn't work if you are in a screen session. if [[ $TERM == screen]; then function precmd() { print -Pn "\033]0;S $TTY:t{%100<...<%~%<<}\007" } elsif etc personally i use a case $TERM in ... screen) ... *) ... construct -- Mikael MagnussonWhat does that do? I put it in my config and I don't see any differences anywhere.
case "$TERM" in screen) some stuff that works for screen ;; xterm*|*xvt*) some stuff that only works in xterms ;; *) some generic stuff that works anywhere ;; esac It gets worse.I have to do similar things that hinge off yet other variables besides $TERM for the same reason as the screen issue you ran into. My users use several different terminal emulators that all set $TERM, correctly, to some appropriate standard like "linux" or "ansi" or "scoansi" or "xterm" etc... But they all also support various special extra functionality via escape codes that they recognize and act on regardless what emulation mode they are in. I have to know do I send FacetWin codes? or Anzio? or xterm? (Xfree86 version6 &up? or SCO's built in? or Sun's?" or TUNemu? or Anita? etc...
There are various ways to try to figure out what the user really has. Most emulators have built in environment variables, or they allow you to define your own in the client-side config, that you can look for on the server side in *profile , if the server daemon supports the client setting arbitrary variables which many don't. Plus if you hop from machine to machine or use su to switch users, you lose the initial environment anyways. Then there is answerback, where you send a \005 immediately followed by a timed read to collect the answerback response, if the emulator supports it. (present for ya, one line answerback that takes advantage of bash's timed read option, using reads prompt to send the ^E and hiding the response from going to the screen.)
[ -z "$MYTERM" ] && read -s -t 1 -p `echo -en "\005"` MYTERM # bash onlyif I could just get rid of those backticks...maybe binary edit the script, never tried... (pathetic attempt at topicality: how to do a timed read in zsh? If you can't do a read that times out then you shouldn't do this at all since not all terminals respond to answerback and so the read will just sit there until the user presses a key. You need to specify a ^M at the end of your answerback string on the client side for this. Putty's syntax is "PuTTY^M")
I need stty comands in there too that hinge off both `uname -s` and $TERM because I use a mix of OS's and stty intr & erase collide when telnet/sshing between platforms.
If you are going to try to get that fancy, then hinging off of $TERM like above is just grazing the surface of the problem. :) You should always quote "$TERM" in the case statement too because sometimes it's empty and that makes an invalid case statement at run time.