Closed akinomyoga closed 2 years ago
Thanks for your PR. I've checked it out and I'm always seeing a "background job" indicator even if there are no bg jobs running:
If you fix that then I'll happily merge.
@petobens Thank you for your review!
I somehow cannot reproduce the behavior. It seems to show the correct number of jobs in my environment. May I ask what is shown with the following commands in your session?
$ _trueline_test_jobs_segment() { jobs; jobs -p; } > jobs.txt
$ TRUELINE_SEGMENTS+=('test_jobs,black,red,bold')
$ cat -v jobs.txt
Also, does it happen with the plain Bash (e.g. started by bash --noprofile --norc
) + trueline? If it only happens with a certain combination of configurations, could you provide me the detailed setup? I'd like to reproduce the problem in my environment if possible.
I doesn't happen with plain bash. I've added the following debug statements to the bg_jobs_segment function:
local pid=$(jobs -p)
echo "$pid"
echo "$(ps -p "$pid" -o command)"
And get:
Dunno what's going on.. I can take a closer look during the week. Any pointers are welcome.
Ah, OK. I could reproduce the problem. I think you can also reproduce it with the plain Bash + trueline + the following setting:
_trueline_test_jobs_segment() { (true); jobs; }
TRUELINE_SEGMENTS+=('test_jobs,black,red,bold')
This is actually a known bug of Bash not clearing up the terminated foreground jobs in PROMPT_COMMAND
, trap handlers and in bind -x
handlers. The behavior you provided in https://github.com/petobens/trueline/pull/46#issuecomment-1179907113 is the characteristic behavior of this bug where the processes reported by jobs
don't actually exist at that timing. I once created patches for Bash [ 91f4cc1 @ r22-fix1 akinomyoga/bash, 92315fb @ r22-fix2 akinomyoga/bash, 1e35061 @ r22-fix3 akinomyoga/bash ], created a draft for the bug report at 3d002f9 @ akinomyoga/bug-report but haven't yet submitted them to Chet. Maybe this is the time to revisit these patches and submit the report.
A workaround for this Bash bug at the script side is just run the command jobs
twice and use the result of the second jobs
:
_trueline_test_jobs_segment() { (true); jobs &>/dev/null; jobs; }
TRUELINE_SEGMENTS+=('test_jobs,black,red,bold')
I pushed a workaround 23fb853 for this issue. I hope this solves the problem in your environment.
Awesome! Thanks!
Fixes #43
There seems to be an existing report #43 by another user, but I have also faced a problem with
trueline
for its behavior overwritingPROMPT_COMMAND
. This PR fixes the problem.Problem
The current setup of
trueline
overwrites the existing value ofPROMPT_COMMAND
, so the setups by other plugins sourced beforetrueline
are all disabled.Bash 5.1 introduced the array
PROMPT_COMMAND
to resolve the conflictingPROMPT_COMMAND
, buttrueline
even completely breaks this new Bash 5.1 feature byunset PROMPT_COMMAND
. With Bash 5.1+, the plugins are supposed to add itsPROMPT_COMMAND
by e.g.PROMPT_COMMAND+=(_plugin_specific_prompt_command)
keeping the existing array elements as is. However, the currenttrueline
removes all the other elements by unsetting the entire array byunset PROMPT_COMMAND
.Solution
With Bash 5.1+, we may just use
PROMPT_COMMAND+=(_trueline_prompt_command)
. To protect it from some older plugins that does not support Bash 5.1+, we can optionally prependPROMPT_COMMAND=${PROMPT_COMMAND-}
as suggested by Martijn in the Bash mailing list [1].With Bash 5.0 and below, we can prepend
_trueline_prompt_command
in the existing value ofPROMPT_COMMAND
.