Re:  (Buglet) job numbers do not get re-used (somet imes)

Wiley Young <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Message-ID <CAGnujaP9GMDv_P94VNyK1gS54SrfX16-ZjmBcxxAZip1Lz9amQ@mail.gmail.com>
>
> Subject: (Buglet) job numbers do not get re-used (sometimes)
>
> I find this annoying because if job #1 exits for some reason (including my
> accidentally
> killing it), I can't get things back to the way they were before (other
> than by getting
> rid of all the jobs and starting over).  In particular, this means I have
> to re-train
> myself to refer to the new job as %4, when I had been used to referring to
> it as %1.


How about using an alias?

~ $ jobs -l
~ $ !sl
~ $ sleep 1000 &
[1] 30898
~ $ sleep 1000 &
[2] 30900
~ $ sleep 1000 &
[3] 30902
~ $ kill %1
~ $
[1] Terminated sleep 1000
~ $ %1
~ $
[2]- Terminated sleep 1000
~ $ jobs -l
[3]+ 30902 Running sleep 1000 &
~ $ %1
~ $
[3]+ Terminated sleep 1000
~ $ %1
%1: no such job
~ $ alias
alias %1='bgpid=$( jobs -l | awk "\$3 !~ /^(Term|Kill).+\$/ && \$2
~/^[0-9]+\$/ { print \$2; exit 0 }" ); if [[ -n ${bgpid} ]]; then kill
"${bgpid}"; else printf "%%1: no such job\n"; fi; unset bgpid'
~ $


Wiley

>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.