Repository navigation
Avoid overwriting existing PROMPT_COMMAND - #46
Conversation
|
@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.txtAlso, does it happen with the plain Bash (e.g. started by |
|
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 A workaround for this Bash bug at the script side is just run the command _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
truelinefor its behavior overwritingPROMPT_COMMAND. This PR fixes the problem.Problem
The current setup of
truelineoverwrites the existing value ofPROMPT_COMMAND, so the setups by other plugins sourced beforetruelineare all disabled.Bash 5.1 introduced the array
PROMPT_COMMANDto resolve the conflictingPROMPT_COMMAND, buttruelineeven completely breaks this new Bash 5.1 feature byunset PROMPT_COMMAND. With Bash 5.1+, the plugins are supposed to add itsPROMPT_COMMANDby e.g.PROMPT_COMMAND+=(_plugin_specific_prompt_command)keeping the existing array elements as is. However, the currenttruelineremoves 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_commandin the existing value ofPROMPT_COMMAND.