Skip to content

Commit 1c82488

Browse files
committed
Rename public functions and variables as "bash_preexec_*"
1 parent dcef4ad commit 1c82488

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

bash-preexec.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ __bp_inside_precmd=0
6060
__bp_inside_preexec=0
6161

6262
# Initial PROMPT_COMMAND string that is removed from PROMPT_COMMAND post __bp_install
63-
__bp_install_string=$'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
63+
bash_preexec_install_string=$'__bp_trap_string="$(trap -p DEBUG)"\ntrap - DEBUG\n__bp_install'
64+
65+
# WARNING: This variable is no longer used and should not be relied upon.
66+
# Use ${bash_preexec_install_string} instead.
67+
__bp_install_string="${bash_preexec_install_string}"
6468

6569
# The command string that is registered to the DEBUG trap.
66-
__bp_trapdebug_string='__bp_preexec_invoke_exec "$_"'
70+
bash_preexec_trapdebug_string='__bp_preexec_invoke_exec "$_"'
6771

6872
# Fails if any of the given variables are readonly
6973
# Reference https://stackoverflow.com/a/4441178
@@ -146,13 +150,13 @@ __bp_precmd_invoke_cmd() {
146150
return
147151
fi
148152
local __bp_inside_precmd=1
149-
__bp_invoke_precmd_functions "$__bp_last_ret_value" "$__bp_last_argument_prev_command"
153+
bash_preexec_invoke_precmd_functions "$__bp_last_ret_value" "$__bp_last_argument_prev_command"
150154
}
151155

152156
# This function invokes every function defined in our function array
153157
# "precmd_function". This function receives the arguments $1 and $2 for $? and
154158
# $_, respectively, that will be set for the precmd functions.
155-
__bp_invoke_precmd_functions() {
159+
bash_preexec_invoke_precmd_functions() {
156160
local __lastexit=$1 __lastarg=$2
157161
# Invoke every function defined in our function array.
158162
local precmd_function
@@ -255,7 +259,7 @@ __bp_preexec_invoke_exec() {
255259
fi
256260

257261
local preexec_ret_value
258-
__bp_invoke_preexec_functions "${__bp_last_ret_value:-}" "$__bp_last_argument_prev_command" "$this_command"
262+
bash_preexec_invoke_preexec_functions "${__bp_last_ret_value:-}" "$__bp_last_argument_prev_command" "$this_command"
259263

260264
# Restore the last argument of the last executed command, and set the return
261265
# value of the DEBUG trap to be the return code of the last preexec function
@@ -273,7 +277,7 @@ __bp_preexec_invoke_exec() {
273277
# (corresponding to BASH_COMMAND in the DEBUG trap). This function assigns the
274278
# last non-zero exit status from the preexec functions to the variable
275279
# `preexec_ret_value`. If there is no error, preexec_ret_value is set to `0`.
276-
__bp_invoke_preexec_functions() {
280+
bash_preexec_invoke_preexec_functions() {
277281
local __lastexit=$1 __lastarg=$2 __this_command=$3
278282
local preexec_function
279283
local preexec_function_ret_value
@@ -300,7 +304,7 @@ __bp_install() {
300304
return 1;
301305
fi
302306

303-
trap "$__bp_trapdebug_string" DEBUG
307+
trap "$bash_preexec_trapdebug_string" DEBUG
304308

305309
# Preserve any prior DEBUG trap as a preexec function
306310
local prior_trap=$(sed "s/[^']*'\(.*\)'[^']*/\1/" <<<"${__bp_trap_string:-}")
@@ -329,8 +333,8 @@ __bp_install() {
329333
local existing_prompt_command
330334
# Remove setting our trap install string and sanitize the existing prompt command string
331335
existing_prompt_command="${PROMPT_COMMAND:-}"
332-
existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
333-
existing_prompt_command="${existing_prompt_command//$__bp_install_string}"
336+
existing_prompt_command="${existing_prompt_command//$bash_preexec_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
337+
existing_prompt_command="${existing_prompt_command//$bash_preexec_install_string}"
334338
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"
335339

336340
# Install our hooks in PROMPT_COMMAND to allow our trap to know when we've
@@ -367,15 +371,15 @@ __bp_install_after_session_init() {
367371
if [[ -n "$sanitized_prompt_command" ]]; then
368372
PROMPT_COMMAND=${sanitized_prompt_command}$'\n'
369373
fi;
370-
PROMPT_COMMAND+=${__bp_install_string}
374+
PROMPT_COMMAND+=${bash_preexec_install_string}
371375
}
372376

373377
# Remove hooks installed in the DEBUG trap and PROMPT_COMMAND.
374-
__bp_uninstall() {
378+
bash_preexec_uninstall() {
375379
# Remove __bp_install hook from PROMPT_COMMAND
376-
if [[ ${PROMPT_COMMAND-} == *"$__bp_install_string"* ]]; then
377-
PROMPT_COMMAND="${PROMPT_COMMAND//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
378-
PROMPT_COMMAND="${PROMPT_COMMAND//$__bp_install_string}"
380+
if [[ ${PROMPT_COMMAND-} == *"$bash_preexec_install_string"* ]]; then
381+
PROMPT_COMMAND="${PROMPT_COMMAND//$bash_preexec_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
382+
PROMPT_COMMAND="${PROMPT_COMMAND//$bash_preexec_install_string}"
379383
fi
380384

381385
# Remove precmd hook from PROMPT_COMMAND
@@ -385,15 +389,15 @@ __bp_uninstall() {
385389

386390
# Remove preexec hook in the DEBUG trap
387391
local q="'" Q="'\''"
388-
if [[ $(trap -p DEBUG) == "trap -- '${__bp_trapdebug_string//$q/$Q}' DEBUG" ]]; then
392+
if [[ $(trap -p DEBUG) == "trap -- '${bash_preexec_trapdebug_string//$q/$Q}' DEBUG" ]]; then
389393
if [[ ${__bp_trap_string-} ]]; then
390394
eval -- "$__bp_trap_string"
391395
else
392396
trap - DEBUG
393397
fi
394398
fi
395399
}
396-
declare -ft __bp_uninstall
400+
declare -ft bash_preexec_uninstall
397401

398402
# Run our install so long as we're not delaying it.
399403
if [[ -z "${__bp_delay_install:-}" ]]; then

0 commit comments

Comments
 (0)