Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Number of jobs in prompt



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



Messages sorted by: Reverse Date, Date, Thread, Author