zsh-workers
 help / color / mirror / code / Atom feed
* Re: Number of jobs in prompt
       [not found] <200110220017.f9M0Hfv24644@nexus.csse.monash.edu.au>
@ 2001-10-31 18:11 ` Oliver Kiddle
  2001-11-01 15:42   ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2001-10-31 18:11 UTC (permalink / raw)
  To: zsh-workers; +Cc: Deborah Ariel Pickett

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Number of jobs in prompt
  2001-10-31 18:11 ` Number of jobs in prompt Oliver Kiddle
@ 2001-11-01 15:42   ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2001-11-01 15:42 UTC (permalink / raw)
  To: zsh-workers

On Oct 31,  6:11pm, Oliver Kiddle wrote:
}
} So any views on whether I should I commit the patch below or not?

[Patch adds %j and %(j.t.f)]

I don't see any reason not to commit it.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-11-01 15:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <200110220017.f9M0Hfv24644@nexus.csse.monash.edu.au>
2001-10-31 18:11 ` Number of jobs in prompt Oliver Kiddle
2001-11-01 15:42   ` Bart Schaefer

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).