From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15731 invoked from network); 31 Oct 2001 18:12:31 -0000 Received: from ns2.primenet.com.au (HELO primenet.com.au) (?Jcffhui2kuAvfYa/2RwN1TVlirp1H7/0?@203.24.36.3) by ns1.primenet.com.au with SMTP; 31 Oct 2001 18:12:31 -0000 Received: (qmail 6421 invoked from network); 31 Oct 2001 18:12:29 -0000 Received: from sunsite.dk (130.225.247.90) by proxy.melb.primenet.com.au with SMTP; 31 Oct 2001 18:12:29 -0000 Received: (qmail 8618 invoked by alias); 31 Oct 2001 18:12:18 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16198 Received: (qmail 8604 invoked from network); 31 Oct 2001 18:12:16 -0000 X-VirusChecked: Checked Sender: kiddleo@cav.logica.co.uk Message-ID: <3BE03EE1.26A8BB70@yahoo.co.uk> Date: Wed, 31 Oct 2001 18:11:45 +0000 From: Oliver Kiddle X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.15 i686) X-Accept-Language: en MIME-Version: 1.0 To: zsh-workers@sunsite.dk CC: Deborah Ariel Pickett Subject: Re: Number of jobs in prompt References: <200110220017.f9M0Hfv24644@nexus.csse.monash.edu.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Le Wang wrote: > > pipe...that makes sense. But looking at the following > code from my .zshrc: > PS1="$(getJobCount) %# " So we have another confused user trying to get a simple figure for the number of jobs in the prompt. I don't blame them, particularly in the piped builtins case. Have we got this covered in the FAQ? I had initially been put off the idea of a %j prompt expansion by this argument: Deborah Ariel Pickett wrote: > > I'm not convinced that this is such a helpful thing, since it is unlikely to > have exactly the right semantics for most people. For instance, some > users are going to care only about stopped jobs, others only > backgrounded jobs, others the combined stopped and backgrounded > jobs. But then we have other cases of prompt expansions which just do something simple that suits many people. I expect the majority of people will want the count of all jobs anyway. Those that want something more can resort to the current set of tricks. So any views on whether I should I commit the patch below or not? I would use it. --- Src/prompt.c Fri Jun 22 10:57:28 2001 +++ Src/prompt.c Wed Oct 31 17:37:09 2001 @@ -202,7 +202,7 @@ putpromptchar(int doprint, int endchar) { char *ss, *tmbuf = NULL, *hostnam; - int t0, arg, test, sep; + int t0, arg, test, sep, j, numjobs; struct tm *tm; time_t timet; Nameddir nd; @@ -286,6 +286,13 @@ if (getegid() == arg) test = 1; break; + case 'j': + for (numjobs = 0, j = 1; j < MAXJOB; j++) + if (jobtab[j].stat && jobtab[j].procs && + !(jobtab[j].stat & STAT_NOPRINT)) numjobs++; + if (numjobs >= arg) + test = 1; + break; case 'l': *bp = '\0'; countprompt(bufline, &t0, 0, 0); @@ -369,6 +376,14 @@ case '!': addbufspc(DIGBUFSIZE); sprintf(bp, "%d", curhist); + bp += strlen(bp); + break; + case 'j': + for (numjobs = 0, j = 1; j < MAXJOB; j++) + if (jobtab[j].stat && jobtab[j].procs && + !(jobtab[j].stat & STAT_NOPRINT)) numjobs++; + addbufspc(DIGBUFSIZE); + sprintf(bp, "%d", numjobs); bp += strlen(bp); break; case 'M': _____________________________________________________________________ This message has been checked for all known viruses by the MessageLabs Virus Scanning Service. For further information visit http://www.messagelabs.com/stats.asp