fix(bash): fix variable leak in Bash integration (#6143)

* fix(bash): quote array expansions to work around custom IFS

* fix(bash): locally set standard IFS for $(jobs -p)

* fix(bash): localize the leaked variable "job"
This commit is contained in:
Koichi Murase 2024-07-30 04:43:41 +09:00 committed by GitHub
parent d96fbc5bcb
commit e1189ed756
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,12 +32,12 @@ starship_preexec() {
# Will be run before the prompt is drawn
starship_precmd() {
# Save the status, because commands in this pipeline will change $?
STARSHIP_CMD_STATUS=$? STARSHIP_PIPE_STATUS=(${PIPESTATUS[@]})
STARSHIP_CMD_STATUS=$? STARSHIP_PIPE_STATUS=("${PIPESTATUS[@]}")
if [[ ${BLE_ATTACHED-} && ${#BLE_PIPESTATUS[@]} -gt 0 ]]; then
STARSHIP_PIPE_STATUS=("${BLE_PIPESTATUS[@]}")
fi
if [[ -n "${BP_PIPESTATUS-}" ]] && [[ "${#BP_PIPESTATUS[@]}" -gt 0 ]]; then
STARSHIP_PIPE_STATUS=(${BP_PIPESTATUS[@]})
STARSHIP_PIPE_STATUS=("${BP_PIPESTATUS[@]}")
fi
# Due to a bug in certain Bash versions, any external process launched
@ -52,7 +52,7 @@ starship_precmd() {
# Original bug: https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00117.html
jobs &>/dev/null
local NUM_JOBS=0
local job NUM_JOBS=0 IFS=$' \t\n'
# Evaluate the number of jobs before running the preserved prompt command, so that tools
# like z/autojump, which background certain jobs, do not cause spurious background jobs
# to be displayed by starship. Also avoids forking to run `wc`, slightly improving perf.