[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
jobs built-in command and PROMPT_COMMAND
From: |
Christoph Anton Mitterer |
Subject: |
jobs built-in command and PROMPT_COMMAND |
Date: |
Fri, 01 Oct 2021 15:00:27 +0200 |
User-agent: |
Evolution 3.42.0-2 |
Hey.
Two things come together here:
a) In my PS1, I display the number of background jobs (\j), but only
when there are any.
So I have more or less something like:
PS1='...$( [ -n "$(jobs)"] && printf '\j')...'
b) Every now and then it happens that I accidentally Ctrl-D to
fast/often, while there are still some stopped background vi or so
running, killing them.
AFAICS, there is no direct way in bash to prevent this (it would be
nice if there was a feature, that ignores Ctrl-D, but *only* when there
are running jobs).
As a workaround I'd do something like:
protect_background_jobs()
{
if [ -n "$(jobs)" ]; then
IGNOREEOF=100
else
unset -v IGNOREEOF
fi
}
PROMPT_COMMAND=protect_background_jobs
which in principle works, but... (see below).
feature requests with respect to (a):
- the filter parameters -r and -s for the jobs built-in:
It would be nice if these could be use in combination (right now the
latter overrides the former)
The reason is that there seems to be a 3rd class of jobs that jobs
prints, namely the "Done" jobs.
Specifying both, -r and -s would then have the effect of showing any
running/stopped but no done jobs.
These done jobs show up once in my above prompt as "0". Of course
there are workarounds to that, but these seem a bit ugly.
- consequentially it would be nice to have an additional -d or so,
which prints just any done jobs.
- it would be nice if there were additional symbols to \j like,
\j{s|r|d}, so that one can easily print the running/stopped bg jobs
separately, without having to do ugly $(jobs -r | wc -l) stuff
with respect to (b):
- (b) kinda breaks (a), cause it seems that when PS1 is evaluated, the
command from (b) somehow still counts as background job that has just
been Done, so $(jobs) gets never empty. Of course one can work around
that, too, but again, makes it a bit messier.
Is that desired or some bug?
Cheers,
Chris.
- jobs built-in command and PROMPT_COMMAND,
Christoph Anton Mitterer <=