From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4160 invoked from network); 14 Sep 1997 02:46:36 -0000 Received: from math.gatech.edu (list@130.207.146.50) by coral.primenet.com.au with SMTP; 14 Sep 1997 02:46:36 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id WAA05605; Sat, 13 Sep 1997 22:40:29 -0400 (EDT) Resent-Date: Sat, 13 Sep 1997 22:39:57 -0400 (EDT) From: Deborah Ariel Pickett Message-Id: <199709140239.MAA22951@molly.cs.monash.edu.au> Subject: Re: can i have jobs in my prompt? To: zsh-users@math.gatech.edu Date: Sun, 14 Sep 1997 12:39:53 +1000 (EST) In-Reply-To: <199709121750.SAA07577@taos.demon.co.uk> from "Andrew Main" at Sep 12, 97 06:50:30 pm Reply-To: tlm@yoyo.cc.monash.edu.au X-TLM-Quote: It's a dinglehopper! X-Mailer: ELM [version 2.4 PL24 ME8b] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Resent-Message-ID: <"lgECZ1.0.8N1.zvq6q"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1015 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu zefram wrote: > Matthias Kopfermann wrote: > >i forget how many jobs are running, especially if they are in the background. > >what would you do here? > function precmd { > if jobs % >& /dev/null; then > psvar=("*") > else > psvar=("") > fi > } Here is something I whipped up many years ago. It would only list stopped jobs, which is what I wanted, because if a job was running I probably already know about it. This goes inside my precmd function. A few things to note: - This lists jobs like this: j[1+ 3- 4] where job 1 is the current job and 3 is the last job and 4 is some other job, just like 'jobs -l' prints. - For running jobs change the -s to -r in the first line. - this creates lots of temporary files in /tmp. If you want them to be cleared up afterwards don't forget to have a trap on EXIT on your interactive shell. - older versions of zsh would print jobs to stderr, not stdout. Alter the first line appropriately. - gawk works in place of nawk if you don't have the latter. - somewhere in my $PROMPT there is a %v that uses the value I put into $psvar[4]. This mailing list flourishes on ideas. I am always looking for new ideas of things to put in my prompt. Presently I list jobs, pwd, folders with new mail, the status of a shat program used here at Monash, and shell level. Anyone else got neat shell prompt stuff? -- Debbie Pickett http://www.cs.monash.edu.au/~debbiep/ tlm@yoyo.cc.monash.edu.au "Welcome to the food chain." - _FernGully_ # Get a list of suspended jobs to put in the command line. # Have to use a temporary file because it's the only way # we can run the jobs builtin and set a variable within the current # shell - doing either of these in a subshell defeats the purpose. # The jobs command outputs to stderr. Use the current hostname # and process ID to ensure that there's no problems even if # /tmp is mounted across filesystems. builtin jobs -s >! /tmp/jobs$HOST$$ if [[ -s /tmp/jobs$HOST$$ ]] then # There's at least one suspended job. Glean the job numbers from # the file. Surround the text with the relevant description and # proper number of spaces. psvar[4]="j`nawk \ '/^\[/ { if (match (\$1, /[0-9]+/)) { jobs = jobs \" \" substr (\$1, RSTART, RLENGTH) } if (match (\$2, /^\+|-$/)) { jobs = jobs \$2 } } END { if (jobs != \"\") { print \"[\" substr (jobs, 2) \"]\" } }' < /tmp/jobs$HOST$$` $XTTITLEBETWEEN" else # No jobs - we can skip the call to nawk. psvar[4]= fi