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

Re: multiple background jobs of the same program



It would appear that on Sun, Sep 14, 1997 at 04:09:10PM -0700, Bart Schaefer wrote:
> On Sep 14,  3:05pm, Adam R. Paul wrote:
> } Subject: Re: multiple background jobs of the same program
> }
> } > Replace the `#' with `;:'.  This works best if you have menu completion
> } > so that the `;' isn't interpreted as a command separator until after you
> } > have a chance to cycle through all the possibilities.
> } 
> } Hmm, it doesn't appear to work at all unless menu_complete is set :(  
> 
> I use automenu, not menucomplete, and it's OK there ....

Hmm, I think I'm using automenu too (its not set explicitly, but it does
show up in my 'unsetopt' completion (which completes on set options), and 
not in my 'setopt' completion (which completes on unset options:) )

> However, it works for me with autolist and listambiguous, at least as far
> as getting the listing:
> 
> zagzig[37] fg <TAB>
> %1 ;: vim fo       %2 ;: info -f zsh  %3 ;: vim bar
> zagzig[37] fg %
> 
> At this point if I hit TAB again I get a beep, and if I supply (say) the
> digit 1 and then hit TAB I encounter what must be a completion bug:
> 
> zagzig[37] fg %1<TAB>
> zagzig[37] fg %^@1
> %1 ;: vim fo       %2 ;: info -f zsh  %3 ;: vim bar
> zagzig[37] fg %
> 
> That ^@ in there is a nul byte that zsh is incorrectly inserting.  It then
> gets erased by compctl -U, but it shouldn't be there to begin with.
> 
> Anyway, the ;: has nothing to do with this particular problem -- get rid of
> the -U if you don't use automenu or menucomplete, and things should be much
> better.
> 
> I just played around with this a bit and discovered that you don't need -U
> at all as long as reply is an empty array (rather than an array containing
> the empty string) when there are no jobs -- which you can do by testing
> whether "jobs" produced any output before running the "sed".  See below.
> 
> } > Either remove the temp file or use >| so `setopt clobber' isn't needed.
> } 
> } I'd love to not use a temp file, but it appears that piping 'jobs' output
> 
> No, I didn't mean don't use the temp file; I meant end the function with
> "rm /tmp/._zshjobcomp.$$".
> 
> Anyway, to summarize:
> 
> listjobs() {
>   jobs >| /tmp/._zshjobcomp.$$ 2>&1
>   if [[ -s /tmp/._zshjobcomp.$$ ]]
>   then
>    reply=( "${(@f)$(sed -e '{
>     s/.\(....\).............\(.*\)/%\1 ;: \2/g
>     s/\]//g
>     s/  */ /g
>     }' /tmp/._zshjobcomp.$$)}" )
>   else
>    reply=()
>   fi
> }
> 
> compctl -Q -K listjobs fg bg kill

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


Thanks again, Bart,
	_Adam

-----
Adam R. Paul    - adamp@xxxxxxx 
SCO Engineering - #include <stddisclaimer.h>

Nshiaththao.  Thcolkathsh iont eth n'aathtaghaa kgandu ouaiaaphu thbakggaghn.  



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