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

Re: renice +20 %%



On Aug 13,  3:22pm, Dave Yost wrote:
>
> I can't see how I would write a shell function that would do something like
> 
>    renice +20 %%

  jr() {
    zmodload -i zsh/parameter
    setopt localoptions noshwordsplit noksharrays extendedglob
    local state
    case $1 in
    (%-) state=$jobstates[(R)*:-:*] ;;
    (%%|%+|) state=$jobstates[(R)*:+:*] ;;
    ((#b)%([0-9]#)) state=$jobstates[$match] ;;
    ([0-9]#) renice +20 $1; return;;
    esac
    renice +20 ${${(s.=.)${${(s.:.)state}[3]}}[1]}
  }


jobstates
     This associative array gives information about the states of the
     jobs currently known. The keys are the job numbers and the values
     are strings of the form `JOB-STATE:MARK:PID=STATE...'. The
     JOB-STATE gives the state the whole job is currently in, one of
     `running', `suspended', or `done'. The MARK is `+' for the current
     job, `-' for the previous job and empty otherwise. This is
     followed by one `PID=STATE' for every process in the job. The PIDs
     are, of course, the process IDs and the STATE describes the state
     of that process.

-- 



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