* If then Prompt
@ 2007-05-24 16:13 fREW
2007-05-24 16:18 ` Mikael Magnusson
0 siblings, 1 reply; 11+ messages in thread
From: fREW @ 2007-05-24 16:13 UTC (permalink / raw)
To: Zsh users list
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?
-fREW
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-24 16:13 If then Prompt fREW
@ 2007-05-24 16:18 ` Mikael Magnusson
2007-05-24 16:29 ` fREW
0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2007-05-24 16:18 UTC (permalink / raw)
To: fREW; +Cc: Zsh users list
On 24/05/07, fREW <frioux@gmail.com> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-24 16:18 ` Mikael Magnusson
@ 2007-05-24 16:29 ` fREW
2007-05-24 17:11 ` Mikael Magnusson
0 siblings, 1 reply; 11+ messages in thread
From: fREW @ 2007-05-24 16:29 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: Zsh users list
On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
> On 24/05/07, fREW <frioux@gmail.com> 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.
host_color=cyan
history_color=yellow
user_color=green
root_color=red
directory_color=magenta
error_color=red
jobs_color=green
host_prompt="%{$fg_bold[$host_color]%}%m%{$reset_color%}"
jobs_prompt1="%{$fg_bold[$jobs_color]%}(%{$reset_color%}"
jobs_prompt2="%{$fg[$jobs_color]%}%j%{$reset_color%}"
jobs_prompt3="%{$fg_bold[$jobs_color]%})%{$reset_color%}"
jobs_total="%(1j.${jobs_prompt1}${jobs_prompt2}${jobs_prompt3} .)"
history_prompt1="%{$fg_bold[$history_color]%}[%{$reset_color%}"
history_prompt2="%{$fg[$history_color]%}%h%{$reset_color%}"
history_prompt3="%{$fg_bold[$history_color]%}]%{$reset_color%}"
history_total="${history_prompt1}${history_prompt2}${history_prompt3}"
error_prompt1="%{$fg_bold[$error_color]%}<%{$reset_color%}"
error_prompt2="%{$fg[$error_color]%}%?%{$reset_color%}"
error_prompt3="%{$fg_bold[$error_color]%}>%{$reset_color%}"
error_total="%(?..${error_prompt1}${error_prompt2}${error_prompt3} )"
if [[ $TERM == xterm ]]; then
directory_prompt=""
else
directory_prompt="%{$fg[$directory_color]%}%~%{$reset_color%} "
fi
if [[ $USER == root ]]; then
post_prompt="%{$fg_bold[$root_color]%}%#%{$reset_color%}"
else
post_prompt="%{$fg_bold[$user_color]%}%#%{$reset_color%}"
fi
PS1="${host_prompt} ${jobs_total}${history_total}
${directory_prompt}${error_total}${post_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.
-fREW
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-24 16:29 ` fREW
@ 2007-05-24 17:11 ` Mikael Magnusson
2007-05-24 18:51 ` fREW
0 siblings, 1 reply; 11+ messages in thread
From: Mikael Magnusson @ 2007-05-24 17:11 UTC (permalink / raw)
To: fREW; +Cc: Zsh users list
On 24/05/07, fREW <frioux@gmail.com> wrote:
> On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
> > On 24/05/07, fREW <frioux@gmail.com> 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 Magnusson
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-24 17:11 ` Mikael Magnusson
@ 2007-05-24 18:51 ` fREW
2007-05-24 22:36 ` Mikael Magnusson
2007-05-25 12:06 ` Brian K. White
0 siblings, 2 replies; 11+ messages in thread
From: fREW @ 2007-05-24 18:51 UTC (permalink / raw)
To: Mikael Magnusson; +Cc: Zsh users list
On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
> On 24/05/07, fREW <frioux@gmail.com> wrote:
> > On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
> > > On 24/05/07, fREW <frioux@gmail.com> 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 Magnusson
>
What does that do? I put it in my config and I don't see any
differences anywhere.
-fREW
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-24 18:51 ` fREW
@ 2007-05-24 22:36 ` Mikael Magnusson
2007-05-25 12:06 ` Brian K. White
1 sibling, 0 replies; 11+ messages in thread
From: Mikael Magnusson @ 2007-05-24 22:36 UTC (permalink / raw)
To: fREW; +Cc: Zsh users list
On 24/05/07, fREW <frioux@gmail.com> wrote:
> On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
> > On 24/05/07, fREW <frioux@gmail.com> wrote:
> > > On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
> > > > On 24/05/07, fREW <frioux@gmail.com> 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 Magnusson
> >
>
> What does that do? I put it in my config and I don't see any
> differences anywhere.
It was supposed to make your xterm title work in screen as well.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-24 18:51 ` fREW
2007-05-24 22:36 ` Mikael Magnusson
@ 2007-05-25 12:06 ` Brian K. White
2007-05-25 13:04 ` Seth Kurtzberg
1 sibling, 1 reply; 11+ messages in thread
From: Brian K. White @ 2007-05-25 12:06 UTC (permalink / raw)
To: zsh-users
----- Original Message -----
From: "fREW" <frioux@gmail.com>
To: "Mikael Magnusson" <mikachu@gmail.com>
Cc: "Zsh users list" <zsh-users@sunsite.dk>
Sent: Thursday, May 24, 2007 2:51 PM
Subject: Re: If then Prompt
> On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
>> On 24/05/07, fREW <frioux@gmail.com> wrote:
>> > On 5/24/07, Mikael Magnusson <mikachu@gmail.com> wrote:
>> > > On 24/05/07, fREW <frioux@gmail.com> 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 Magnusson
>>
>
> What 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 only
if 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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: If then Prompt
2007-05-25 12:06 ` Brian K. White
@ 2007-05-25 13:04 ` Seth Kurtzberg
2007-05-25 13:32 ` Brian K. White
0 siblings, 1 reply; 11+ messages in thread
From: Seth Kurtzberg @ 2007-05-25 13:04 UTC (permalink / raw)
To: zsh-users
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 only
if I could just get rid of those backticks...maybe binary edit the script,
never tried...
use:
... $(echo -en "\005") ...
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-25 13:04 ` Seth Kurtzberg
@ 2007-05-25 13:32 ` Brian K. White
2007-05-25 13:39 ` Peter Stephenson
0 siblings, 1 reply; 11+ messages in thread
From: Brian K. White @ 2007-05-25 13:32 UTC (permalink / raw)
To: zsh-users
----- Original Message -----
From: "Seth Kurtzberg" <seth@cql.com>
To: <zsh-users@sunsite.dk>
Sent: Friday, May 25, 2007 9:04 AM
Subject: RE: If then Prompt
> [ -z "$MYTERM" ] && read -s -t 1 -p `echo -en "\005"` MYTERM # bash
> only
> if I could just get rid of those backticks...maybe binary edit the script,
> never tried...
>
> use:
> ... $(echo -en "\005") ...
It's not the backticks litterally, it's running a child process just to get
a certain character in a certain spot.
Brian K. White brian@aljex.com http://www.myspace.com/KEYofR
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-25 13:32 ` Brian K. White
@ 2007-05-25 13:39 ` Peter Stephenson
2007-05-25 14:07 ` Brian K. White
0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2007-05-25 13:39 UTC (permalink / raw)
To: zsh-users
"Brian K. White" wrote:
> From: "Seth Kurtzberg" <seth@cql.com>
> To: <zsh-users@sunsite.dk>
> Sent: Friday, May 25, 2007 9:04 AM
> Subject: RE: If then Prompt
>
> > [ -z "$MYTERM" ] && read -s -t 1 -p `echo -en "\005"` MYTERM # bash
> > only
> > if I could just get rid of those backticks...maybe binary edit the script,
> > never tried...
> >
> > use:
> > ... $(echo -en "\005") ...
>
> It's not the backticks litterally, it's running a child process just to get
> a certain character in a certain spot.
Sorry, I was dozing the first time this came round...
use $'\005' instead of the backtick expression. This works in both bash
and zsh.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: If then Prompt
2007-05-25 13:39 ` Peter Stephenson
@ 2007-05-25 14:07 ` Brian K. White
0 siblings, 0 replies; 11+ messages in thread
From: Brian K. White @ 2007-05-25 14:07 UTC (permalink / raw)
To: zsh-users
----- Original Message -----
From: "Peter Stephenson" <pws@csr.com>
To: <zsh-users@sunsite.dk>
Sent: Friday, May 25, 2007 9:39 AM
Subject: Re: If then Prompt
> "Brian K. White" wrote:
>> From: "Seth Kurtzberg" <seth@cql.com>
>> To: <zsh-users@sunsite.dk>
>> Sent: Friday, May 25, 2007 9:04 AM
>> Subject: RE: If then Prompt
>>
>> > [ -z "$MYTERM" ] && read -s -t 1 -p `echo -en "\005"` MYTERM # bash
>> > only
>> > if I could just get rid of those backticks...maybe binary edit the
>> > script,
>> > never tried...
>
> use $'\005' instead of the backtick expression. This works in both bash
> and zsh.
Niiiice. Thanks much.
Brian K. White brian@aljex.com http://www.myspace.com/KEYofR
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++.
filePro BBx Linux SCO FreeBSD #callahans Satriani Filk!
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-05-25 14:07 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-24 16:13 If then Prompt fREW
2007-05-24 16:18 ` Mikael Magnusson
2007-05-24 16:29 ` fREW
2007-05-24 17:11 ` Mikael Magnusson
2007-05-24 18:51 ` fREW
2007-05-24 22:36 ` Mikael Magnusson
2007-05-25 12:06 ` Brian K. White
2007-05-25 13:04 ` Seth Kurtzberg
2007-05-25 13:32 ` Brian K. White
2007-05-25 13:39 ` Peter Stephenson
2007-05-25 14:07 ` Brian K. White
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).