zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: zsh-workers@sunsite.dk
Cc: Deborah Ariel Pickett <debbiep@mail.csse.monash.edu.au>
Subject: Re: Number of jobs in prompt
Date: Wed, 31 Oct 2001 18:11:45 +0000	[thread overview]
Message-ID: <3BE03EE1.26A8BB70@yahoo.co.uk> (raw)
In-Reply-To: <200110220017.f9M0Hfv24644@nexus.csse.monash.edu.au>

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


       reply	other threads:[~2001-10-31 18:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200110220017.f9M0Hfv24644@nexus.csse.monash.edu.au>
2001-10-31 18:11 ` Oliver Kiddle [this message]
2001-11-01 15:42   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3BE03EE1.26A8BB70@yahoo.co.uk \
    --to=okiddle@yahoo.co.uk \
    --cc=debbiep@mail.csse.monash.edu.au \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).