@@ -151,11 +151,15 @@ __bp_precmd_invoke_cmd() {
151
151
152
152
# This function invokes every function defined in our function array
153
153
# "precmd_function". This function receives the arguments $1 and $2 for $? and
154
- # $_, respectively, that will be set for the precmd functions.
154
+ # $_, respectively, that will be set for the precmd functions. This function
155
+ # returns the last non-zero exit status of the hook functions. If there is no
156
+ # error, this function returns 0.
155
157
bash_preexec_invoke_precmd_functions () {
156
158
local lastexit=$1 lastarg=$2
157
159
# Invoke every function defined in our function array.
158
160
local precmd_function
161
+ local precmd_function_ret_value
162
+ local precmd_ret_value=0
159
163
for precmd_function in " ${precmd_functions[@]} " ; do
160
164
161
165
# Only execute this function if it actually exists.
@@ -164,8 +168,13 @@ bash_preexec_invoke_precmd_functions() {
164
168
__bp_set_ret_value " $lastexit " " $lastarg "
165
169
# Quote our function invocation to prevent issues with IFS
166
170
" $precmd_function "
171
+ precmd_function_ret_value=$?
172
+ if [[ " $precmd_function_ret_value " != 0 ]]; then
173
+ precmd_ret_value=" $precmd_function_ret_value "
174
+ fi
167
175
fi
168
176
done
177
+ return " $precmd_ret_value "
169
178
}
170
179
171
180
# Sets a return value in $?. We may want to get access to the $? variable in our
@@ -254,8 +263,8 @@ __bp_preexec_invoke_exec() {
254
263
return
255
264
fi
256
265
257
- local preexec_ret_value
258
266
bash_preexec_invoke_preexec_functions " ${__bp_last_ret_value:- } " " $__bp_last_argument_prev_command " " $this_command "
267
+ local preexec_ret_value=$?
259
268
260
269
# Restore the last argument of the last executed command, and set the return
261
270
# value of the DEBUG trap to be the return code of the last preexec function
@@ -270,14 +279,14 @@ __bp_preexec_invoke_exec() {
270
279
# "preexec_function". This function receives the arguments $1 and $2 for $?
271
280
# and $_, respectively, that will be set for the preexec functions. The third
272
281
# argument $3 specifies the user command that is going to be executed
273
- # (corresponding to BASH_COMMAND in the DEBUG trap). This function assigns the
274
- # last non-zero exit status from the preexec functions to the variable
275
- # `preexec_ret_value`. If there is no error, preexec_ret_value is set to `0`.
282
+ # (corresponding to BASH_COMMAND in the DEBUG trap). This function returns the
283
+ # last non-zero exit status from the preexec functions. If there is no error,
284
+ # this function returns `0`.
276
285
bash_preexec_invoke_preexec_functions () {
277
286
local lastexit=$1 lastarg=$2 this_command=$3
278
287
local preexec_function
279
288
local preexec_function_ret_value
280
- preexec_ret_value=0
289
+ local preexec_ret_value=0
281
290
for preexec_function in " ${preexec_functions[@]:- } " ; do
282
291
283
292
# Only execute each function if it actually exists.
@@ -292,6 +301,7 @@ bash_preexec_invoke_preexec_functions() {
292
301
fi
293
302
fi
294
303
done
304
+ return " $preexec_ret_value "
295
305
}
296
306
297
307
__bp_install () {
0 commit comments