@@ -40,6 +40,9 @@ if [[ "$__bp_imported" == "defined" ]]; then
40
40
fi
41
41
__bp_imported=" defined"
42
42
43
+ # Should be available to each precmd and preexec
44
+ # functions, should they want it.
45
+ __bp_last_command_ret_value=" $? "
43
46
44
47
# Remove ignorespace and or replace ignoreboth from HISTCONTROL
45
48
# so we can accurately invoke preexec with a command from our
@@ -81,7 +84,7 @@ __bp_interactive_mode() {
81
84
__bp_precmd_invoke_cmd () {
82
85
83
86
# Should be available to each precmd function, should it want it.
84
- local ret_value =" $? "
87
+ __bp_last_ret_value =" $? "
85
88
86
89
# For every function defined in our function array. Invoke it.
87
90
local precmd_function
@@ -90,7 +93,7 @@ __bp_precmd_invoke_cmd() {
90
93
# Only execute this function if it actually exists.
91
94
# Test existence of functions with: declare -[Ff]
92
95
if type -t " $precmd_function " 1> /dev/null; then
93
- __bp_set_ret_value $ret_value
96
+ __bp_set_ret_value $__bp_last_ret_value
94
97
$precmd_function
95
98
fi
96
99
done
@@ -130,14 +133,19 @@ __bp_in_prompt_command() {
130
133
# interactively, and invoke 'preexec' if so.
131
134
__bp_preexec_invoke_exec () {
132
135
133
- if [[ -n " $COMP_LINE " ]]
134
- then
135
- # We're in the middle of a completer. This obviously can't be
136
+ # Checks if the file descriptor is not standard out (i.e. '1')
137
+ # __bp_delay_install checks if we're in test. Needed for bats to run.
138
+ # Prevents preexec from being invoked for functions in PS1
139
+ if [[ ! -t 1 && -z " $__bp_delay_install " ]]; then
140
+ return
141
+ fi
142
+
143
+ if [[ -n " $COMP_LINE " ]]; then
144
+ # We're in the middle of a completer. This obviously can't be
136
145
# an interactively issued command.
137
146
return
138
147
fi
139
- if [[ -z " $__bp_preexec_interactive_mode " ]]
140
- then
148
+ if [[ -z " $__bp_preexec_interactive_mode " ]]; then
141
149
# We're doing something related to displaying the prompt. Let the
142
150
# prompt set the title instead of me.
143
151
return
@@ -147,16 +155,14 @@ __bp_preexec_invoke_exec() {
147
155
# In other words, if you have a subshell like
148
156
# (sleep 1; sleep 2)
149
157
# You want to see the 'sleep 2' as a set_command_title as well.
150
- if [[ 0 -eq " $BASH_SUBSHELL " ]]
151
- then
158
+ if [[ 0 -eq " $BASH_SUBSHELL " ]]; then
152
159
__bp_preexec_interactive_mode=" "
153
160
fi
154
161
fi
155
162
156
163
if __bp_in_prompt_command " $BASH_COMMAND " ; then
157
164
# If we're executing something inside our prompt_command then we don't
158
165
# want to call preexec. Bash prior to 3.1 can't detect this at all :/
159
-
160
166
__bp_preexec_interactive_mode=" "
161
167
return
162
168
fi
@@ -180,6 +186,7 @@ __bp_preexec_invoke_exec() {
180
186
# Only execute each function if it actually exists.
181
187
# Test existence of function with: declare -[fF]
182
188
if type -t " $preexec_function " 1> /dev/null; then
189
+ __bp_set_ret_value $__bp_last_ret_value
183
190
$preexec_function " $this_command "
184
191
fi
185
192
done
@@ -201,6 +208,11 @@ __bp_preexec_and_precmd_install() {
201
208
# Adjust our HISTCONTROL Variable if needed.
202
209
__bp_adjust_histcontrol
203
210
211
+
212
+ # Set so debug trap will work be invoked in subshells.
213
+ set -o functrace > /dev/null 2>&1
214
+ shopt -s extdebug > /dev/null 2>&1
215
+
204
216
# Take our existing prompt command and append a semicolon to it
205
217
# if it doesn't already have one.
206
218
local existing_prompt_command
0 commit comments