Don't downcast PROMPT_COMMAND

Since bash 5.0 PROMPT_COMMAND is an array. Lets not turn it into a string.
Copied from https://github.com/direnv/direnv/blob/master/internal/cmd/shell_bash.go#L19-L23
This commit is contained in:
Sandro 2025-04-08 15:13:35 +02:00 committed by GitHub
parent b193a84eb0
commit a88bb34387
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -55,7 +55,11 @@ function __zoxide_hook() {
# Initialize hook.
if [[ ${PROMPT_COMMAND:=} != *'__zoxide_hook'* ]]; then
PROMPT_COMMAND="__zoxide_hook;${PROMPT_COMMAND#;}"
if [[ "$(declare -p PROMPT_COMMAND 2>&1)" == "declare -a"* ]]; then
PROMPT_COMMAND=(__zoxide_hook "${PROMPT_COMMAND[@]}")
else
PROMPT_COMMAND="__zoxide_hook;${PROMPT_COMMAND#;}"
fi
fi
{%- endif %}