Skip to content

Commit 552d266

Browse files
gaelicWizardrcaloras
authored andcommitted
Handle unbound PROMPT_COMMAND
Expressly handle if $PROMPT_COMMAND is previously undefined.
1 parent 10b41c5 commit 552d266

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

bash-preexec.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ __bp_set_ret_value() {
159159
__bp_in_prompt_command() {
160160

161161
local prompt_command_array
162-
IFS=$'\n;' read -rd '' -a prompt_command_array <<< "$PROMPT_COMMAND"
162+
IFS=$'\n;' read -rd '' -a prompt_command_array <<< "${PROMPT_COMMAND:-}"
163163

164164
local trimmed_arg
165165
__bp_trim_whitespace trimmed_arg "${1:-}"
@@ -297,7 +297,8 @@ __bp_install() {
297297

298298
local existing_prompt_command
299299
# Remove setting our trap install string and sanitize the existing prompt command string
300-
existing_prompt_command="${PROMPT_COMMAND//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
300+
existing_prompt_command="${PROMPT_COMMAND:-}"
301+
existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
301302
existing_prompt_command="${existing_prompt_command//$__bp_install_string}"
302303
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"
303304

@@ -328,7 +329,7 @@ __bp_install_after_session_init() {
328329
__bp_require_not_readonly PROMPT_COMMAND HISTCONTROL HISTTIMEFORMAT || return
329330

330331
local sanitized_prompt_command
331-
__bp_sanitize_string sanitized_prompt_command "$PROMPT_COMMAND"
332+
__bp_sanitize_string sanitized_prompt_command "${PROMPT_COMMAND:-}"
332333
if [[ -n "$sanitized_prompt_command" ]]; then
333334
PROMPT_COMMAND=${sanitized_prompt_command}$'\n'
334335
fi;

0 commit comments

Comments
 (0)