zsh-workers
 help / color / mirror / code / Atom feed
* Re: multiple background jobs of the same program
       [not found]         ` <19970914200202.04363@sco.com>
@ 1997-09-15 11:16           ` Stefan Monnier
  1997-09-15 11:26             ` Stefan Monnier
  1997-09-15 11:34             ` Peter Stephenson
  0 siblings, 2 replies; 5+ messages in thread
From: Stefan Monnier @ 1997-09-15 11:16 UTC (permalink / raw)
  To: zsh-workers

"Adam R. Paul" <adamp@sco.com> writes:
> Thanks much again!  That's _almost_ perfect :)  The only remaining thing is
> that if a job is suspended due to tty output/input, the sed script doesn't
> quite do the right thing (the completion looks like:
> 
> fg %1 ;: tty output) vi foo
> 
> which then gives a parse error if you hit <return> due to the unmatched ')'.
> Oh well, no biggie:)

Good point, here is a version that should correctly ignore the "(tty input)"
thingie if present:

    complete_listjobs() {
      tmpfile=$TMP/zshjobcomp.$$
      jobs >| $tmpfile 2>&1
      if [[ -s $tmpfile ]] then
        reply=( "${(@f)$(sed -e '{
          s/suspended (tty [a-z]*put)/suspended/
          s/^\[\([0-9]*\)\][-+ ]*\([0-9]* *\)[a-z][a-z]*  *\(.*\)/%\1 ;: \2\3/
          }' $tmpfile)}" )
      else
        reply=()
      fi
    }
    
    compctl -Q -K complete_listjobs fg bg kill


-- Stefan


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

* Re: multiple background jobs of the same program
  1997-09-15 11:16           ` Stefan Monnier
@ 1997-09-15 11:26             ` Stefan Monnier
       [not found]               ` <970915075634.ZM30556@candle.brasslantern.com>
  1997-09-15 11:34             ` Peter Stephenson
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 1997-09-15 11:26 UTC (permalink / raw)
  To: zsh-workers

Stefan Monnier <monnier+lists/zsh/workers/news/@tequila.cs.yale.edu> writes:
> Good point, here is a version that should correctly ignore the "(tty input)"
> thingie if present:

I must be stupid, because a much simpler alternative works just as well if not
better:

    complete_listjobs() {
      tmpfile=$TMP/zshjobcomp.$$
      jobs >| $tmpfile 2>&1
      if [[ -s $tmpfile ]] then
        reply=( "${(@f)$(sed -e '{
          s/^\[\([0-9]*\)\][-+ ]*/%\1 ;: /
          }' $tmpfile)}" )
      else
        reply=()
      fi
    }
    
    compctl -Q -K complete_listjobs fg bg kill


-- Stefan

PS: a few improvements possible:

- only list the plainly suspended jobs (and not waiting on tty) for bg
- aknowledge the fact that kill has more uses than to kill jobs. the jobs
  completion should only work once "%" is entered. "ls /proc" might be used
  as well as "kill -l" for other cases.


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

* Re: multiple background jobs of the same program
  1997-09-15 11:16           ` Stefan Monnier
  1997-09-15 11:26             ` Stefan Monnier
@ 1997-09-15 11:34             ` Peter Stephenson
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1997-09-15 11:34 UTC (permalink / raw)
  To: Zsh hackers list

In case it helps, here's a function I posted some time ago to enable
completion of jobs along the lines required.  The difference is
essentially that it relies on interactivecomments, putting the
job description in a comment, e.g.

% kill %1  # sleep 10 

so parsing isn't a problem.  Otherwise it's not so different.  Again,
some kind of menu-like completion is best.

# Function to complete jobnames, with a commented description, as
# suggested by Harmanjit Singh.
# Author:  pws@ifh.de (Peter Stephenson)
# Usage:  with a compctl such as
#   compctl -Q -K jobfunc -x 's[-] p[1,1]' -k signals -- kill

# Make sure interactivecomments is on in the shell running the function.
unsetopt localoptions
setopt interactivecomments

# Use a temporary file to store the jobs, since we can't use a pipe.
local tmpf=/tmp/zshjobs$$

# Get the jobs list: looks like
# [1]  + running    sleep 30
jobs >&! $tmpf
reply=()

local job jobno
while read -A job
do
   # Extract the job no. from the square brackets
   jobno=$job[1]
   jobno=${${jobno#\[}%\]}

   shift job
   # If this job is marked as - or +, the command starts at the
   # fourth field, else at the third.
   [[ $job[1] = [-+] ]] && shift job
   shift job
   # Now the remaining elements of $job contain the command description.
   # Add the whole completion to the reply.
   reply[$#reply+1]="%$jobno  # $job"
done < $tmpf

# Tidy up the job file.
rm $tmpf


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

* Re: multiple background jobs of the same program
       [not found]               ` <970915075634.ZM30556@candle.brasslantern.com>
@ 1997-09-15 23:48                 ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 1997-09-15 23:48 UTC (permalink / raw)
  To: zsh-workers

"Bart Schaefer" <schaefer@brasslantern.com> writes:
> What's $TMP ?  When I first cut'n'pasted this, I got

Nothing. I just happen to use /tmp/monnier instead of /tmp
and many apps honor the TMP envvar for that (others use TMPDIR instead).
I guess it would be nice if TMPPREFIX could take TMP (or TMPDIR) into account.


        Stefan


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

* Re: multiple background jobs of the same program
       [not found]     ` <19970914150505.11879@sco.com>
@ 1997-09-14 23:05       ` Stefan Monnier
       [not found]       ` <970914160910.ZM23900@candle.brasslantern.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 1997-09-14 23:05 UTC (permalink / raw)
  To: zsh-workers

"Adam R. Paul" <adamp@sco.com> writes:
> > listjobs() {
> >   jobs >| /tmp/._zshjobcomp.$$ 2>&1
> >   reply=( "${(@f)$(sed -e '{
> >     s/.\(....\).............\(.*\)/%\1 ;: \2/g
> >     s/\]//g
> >     s/  */ /g
> >     }' /tmp/._zshjobcomp.$$)}" )
> > }
> > 
> > compctl -U -Q -K listjobs fg bg kill
> 
> Thanks very much!  Now if I can only get it to work without having 
> menu_complete set, I'll be one happier camper ;-)

I don't like menu_complete either, but it seems that dropping the -U
is enough to make it work in my case (I have about zero knowledge of the
compctl command). One other thing is: I have "jobs" aliased to "jobs -l"
(why would anyone not see the PIDs is beyond me), so I've had to tweak the
regexp. I've seriously tightened it and in the end it looks like this (it
should work whether your "jobs" is aliased to "jobs -l" or not):

complete_listjobs() {
  jobs >| $TMP/zshjobcomp.$$ 2>&1
  reply=( "${(@f)$(sed -e '{
    s/^\[\([0-9][0-9]*\)\] *[-+ ] *\([0-9]* \)[a-z][a-z]*  *\(.*\)/%\1 ;: \2\3/
    }' $TMP/zshjobcomp.$$)}" )
}

compctl -Q -K complete_listjobs fg bg kill


        Stefan


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

end of thread, other threads:[~1997-09-15 23:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <9709140326.AA21133@cryptica.UCSD.EDU>
     [not found] ` <19970914102839.45957@sco.com>
     [not found]   ` <970914121042.ZM22784@candle.brasslantern.com>
     [not found]     ` <19970914150505.11879@sco.com>
1997-09-14 23:05       ` multiple background jobs of the same program Stefan Monnier
     [not found]       ` <970914160910.ZM23900@candle.brasslantern.com>
     [not found]         ` <19970914200202.04363@sco.com>
1997-09-15 11:16           ` Stefan Monnier
1997-09-15 11:26             ` Stefan Monnier
     [not found]               ` <970915075634.ZM30556@candle.brasslantern.com>
1997-09-15 23:48                 ` Stefan Monnier
1997-09-15 11:34             ` Peter Stephenson

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