From a88bb34387949f82be164763b95a909ee5c878f2 Mon Sep 17 00:00:00 2001 From: Sandro Date: Tue, 8 Apr 2025 15:13:35 +0200 Subject: [PATCH] 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 --- templates/bash.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/templates/bash.txt b/templates/bash.txt index a4177a8..ed4b422 100644 --- a/templates/bash.txt +++ b/templates/bash.txt @@ -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 %}