From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27192 invoked from network); 5 Sep 2007 15:57:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.3 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Sep 2007 15:57:47 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 15942 invoked from network); 5 Sep 2007 15:57:40 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Sep 2007 15:57:40 -0000 Received: (qmail 4042 invoked by alias); 5 Sep 2007 15:57:26 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 11818 Received: (qmail 4033 invoked from network); 5 Sep 2007 15:57:25 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 5 Sep 2007 15:57:25 -0000 Received: (qmail 14709 invoked from network); 5 Sep 2007 15:57:25 -0000 Received: from cluster-g.mailcontrol.com (85.115.41.190) by a.mx.sunsite.dk with SMTP; 5 Sep 2007 15:57:17 -0000 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly15g.srv.mailcontrol.com (MailControl) with ESMTP id l85FtHP4017064 for ; Wed, 5 Sep 2007 16:57:04 +0100 Received: from news01.csr.com ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.1830); Wed, 5 Sep 2007 16:55:41 +0100 Date: Wed, 5 Sep 2007 16:55:41 +0100 From: Peter Stephenson To: zsh-users@sunsite.dk Subject: Re: fg jobs info Message-ID: <20070905165541.7ad048d4@news01.csr.com> In-Reply-To: <070905083002.ZM27536@torch.brasslantern.com> References: <20070902154306.35880.qmail@smasher.org> <070902105953.ZM22915@torch.brasslantern.com> <20070903163147.GA14017@mastermind> <20070904111631.81486.qmail@smasher.org> <070904083104.ZM25598@torch.brasslantern.com> <20070905090302.72429.qmail@smasher.org> <200709050928.l859Su9h016042@news01.csr.com> <070905083002.ZM27536@torch.brasslantern.com> Organization: CSR X-Mailer: Claws Mail 2.10.0 (GTK+ 2.10.14; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 05 Sep 2007 15:55:41.0802 (UTC) FILETIME=[3618DCA0:01C7EFD5] X-Scanned-By: MailControl A-07-08-10 (www.mailcontrol.com) on 10.71.0.125 On Wed, 05 Sep 2007 08:30:00 -0700 Bart Schaefer wrote: > On Sep 5, 10:28am, Peter Stephenson wrote: > } > } > add a variable that automagically returns the text of the > } > fg'd job. > } > } That's $jobtexts. > > Well ... > > $jobtexts returns the text of any/all of the jobs, by job number. > > That doesn't solve the problem of knowing which job number is the job > in the foreground. It's easy and probably useful to make it possible to look up jobs in the special variables by non-numeric arguments, as below. You only get normal job numbers back out when scanning keys, however. > OTOH, I can't figure out how knowing that could be useful, because > when a job is in the foreground the shell is blocked in zwaitjob(), > so there's no way for it to do anything useful with the job text. It doesn't fix this, however. Index: Doc/Zsh/mod_parameter.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_parameter.yo,v retrieving revision 1.7 diff -u -r1.7 mod_parameter.yo --- Doc/Zsh/mod_parameter.yo 17 Sep 2006 19:28:46 -0000 1.7 +++ Doc/Zsh/mod_parameter.yo 5 Sep 2007 15:51:19 -0000 @@ -124,11 +124,19 @@ item(tt(jobdirs))( This associative array maps job numbers to the directories from which the job was started (which may not be the current directory of the job). + +The keys of the associative arrays are usually valid job numbers, +and these are the values output with, for example, tt(${(k)jobdirs}). +Non-numeric job references may be used when looking up a value; +for example, tt(${jobdirs[%+]}) refers to the current job. ) vindex(jobtexts) item(tt(jobtexts))( This associative array maps job numbers to the texts of the command lines that were used to start the jobs. + +Handling of the keys of the associative array is as described for +tt(jobdirs) above. ) vindex(jobstates) item(tt(jobstates))( @@ -142,6 +150,9 @@ otherwise. This is followed by one `var(pid)tt(=)var(state)' for every process in the job. The var(pid)s are, of course, the process IDs and the var(state) describes the state of that process. + +Handling of the keys of the associative array is as described for +tt(jobdirs) above. ) vindex(nameddirs) item(tt(nameddirs))( Index: Src/jobs.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/jobs.c,v retrieving revision 1.59 diff -u -r1.59 jobs.c --- Src/jobs.c 4 Sep 2007 20:43:52 -0000 1.59 +++ Src/jobs.c 5 Sep 2007 15:51:20 -0000 @@ -1468,8 +1468,8 @@ * to a job number. */ /**/ -static int -getjob(char *s, char *prog) +mod_export int +getjob(const char *s, const char *prog) { int jobnum, returnval, mymaxjob; Job myjobtab; @@ -1489,7 +1489,8 @@ /* "%%", "%+" and "%" all represent the current job */ if (*s == '%' || *s == '+' || !*s) { if (curjob == -1) { - zwarnnam(prog, "no current job"); + if (prog) + zwarnnam(prog, "no current job"); returnval = -1; goto done; } @@ -1499,7 +1500,8 @@ /* "%-" represents the previous job */ if (*s == '-') { if (prevjob == -1) { - zwarnnam(prog, "no previous job"); + if (prog) + zwarnnam(prog, "no previous job"); returnval = -1; goto done; } @@ -1521,7 +1523,8 @@ returnval = jobnum; goto done; } - zwarnnam(prog, "%%%s: no such job", s); + if (prog) + zwarnnam(prog, "%%%s: no such job", s); returnval = -1; goto done; } @@ -1538,7 +1541,8 @@ returnval = jobnum; goto done; } - zwarnnam(prog, "job not found: %s", s); + if (prog) + zwarnnam(prog, "job not found: %s", s); returnval = -1; goto done; } @@ -2299,7 +2303,7 @@ /**/ int -findjobnam(char *s) +findjobnam(const char *s) { int jobnum; Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.166 diff -u -r1.166 utils.c --- Src/utils.c 30 Aug 2007 15:18:25 -0000 1.166 +++ Src/utils.c 5 Sep 2007 15:51:22 -0000 @@ -5017,7 +5017,7 @@ /**/ mod_export int -strpfx(char *s, char *t) +strpfx(const char *s, const char *t) { while (*s && *s == *t) s++, t++; Index: Src/Modules/parameter.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v retrieving revision 1.44 diff -u -r1.44 parameter.c --- Src/Modules/parameter.c 6 Jul 2007 21:52:40 -0000 1.44 +++ Src/Modules/parameter.c 5 Sep 2007 15:51:23 -0000 @@ -1007,13 +1007,18 @@ { Param pm = NULL; int job; + char *pend; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR | PM_READONLY; pm->gsu.s = &nullsetscalar_gsu; - if ((job = atoi(name)) >= 1 && job <= maxjob && + job = strtod(name, &pend); + /* Non-numeric keys are looked up by job name */ + if (*pend) + job = getjob(name, NULL); + if (job >= 1 && job <= maxjob && jobtab[job].stat && jobtab[job].procs && !(jobtab[job].stat & STAT_NOPRINT)) pm->u.str = pmjobtext(job); @@ -1104,13 +1109,17 @@ { Param pm = NULL; int job; + char *pend; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR | PM_READONLY; pm->gsu.s = &nullsetscalar_gsu; - if ((job = atoi(name)) >= 1 && job <= maxjob && + job = strtod(name, &pend); + if (*pend) + job = getjob(name, NULL); + if (job >= 1 && job <= maxjob && jobtab[job].stat && jobtab[job].procs && !(jobtab[job].stat & STAT_NOPRINT)) pm->u.str = pmjobstate(job); @@ -1166,13 +1175,17 @@ { Param pm = NULL; int job; + char *pend; pm = (Param) hcalloc(sizeof(struct param)); pm->node.nam = dupstring(name); pm->node.flags = PM_SCALAR | PM_READONLY; pm->gsu.s = &nullsetscalar_gsu; - if ((job = atoi(name)) >= 1 && job <= maxjob && + job = strtod(name, &pend); + if (*pend) + job = getjob(name, NULL); + if (job >= 1 && job <= maxjob && jobtab[job].stat && jobtab[job].procs && !(jobtab[job].stat & STAT_NOPRINT)) pm->u.str = pmjobdir(job); .