@@ -27,32 +27,25 @@ __bp_install_after_session_init
27
27
28
28
# # Helper functions
29
29
function __check_precmd_conflict() {
30
- local f # TODO: trim whitespace like preexec does
31
- for f in " ${precmd_functions[@]} " ; do
32
- if [[ " ${f} " == " ${1} " ]]; then
33
- return 0
34
- fi
35
- done
36
- return 1
30
+ local f
31
+ __bp_trim_whitespace f " ${1?} "
32
+ ! _bash-it-array-contains-element " ${f} " " ${precmd_functions[@]} "
37
33
}
38
34
39
35
function __check_preexec_conflict() {
40
- local f # TODO: trim whitespace like preexec does
41
- for f in " ${preexec_functions[@]} " ; do
42
- if [[ " ${f} " == " ${1} " ]]; then
43
- return 0
44
- fi
45
- done
46
- return 1
36
+ local f
37
+ __bp_trim_whitespace f " ${1?} "
38
+ ! _bash-it-array-contains-element " ${f} " " ${preexec_functions[@]} "
47
39
}
48
40
49
41
function safe_append_prompt_command {
50
- local prompt_re
42
+ local prompt_re f
43
+ __bp_trim_whitespace f " ${1?} "
51
44
52
45
if [ " ${__bp_imported:- missing} " == " defined" ]; then
53
46
# We are using bash-preexec
54
- if ! __check_precmd_conflict " ${1 } " ; then
55
- precmd_functions+=(" ${1 } " )
47
+ if ! __check_precmd_conflict " ${f } " ; then
48
+ precmd_functions+=(" ${f } " )
56
49
fi
57
50
else
58
51
# Set OS dependent exact match regular expression
@@ -75,12 +68,13 @@ function safe_append_prompt_command {
75
68
}
76
69
77
70
function safe_append_preexec {
78
- local prompt_re
71
+ local prompt_re f
72
+ __bp_trim_whitespace f " ${1?} "
79
73
80
74
if [ " ${__bp_imported:- missing} " == " defined" ]; then
81
75
# We are using bash-preexec
82
- if ! __check_preexec_conflict " ${1 } " ; then
83
- preexec_functions+=(" ${1 } " )
76
+ if ! __check_preexec_conflict " ${f } " ; then
77
+ preexec_functions+=(" ${f } " )
84
78
fi
85
79
else
86
80
_log_error " ${FUNCNAME[0]} : can't append to preexec hook because _bash-preexec.sh_ hasn't been loaded"
0 commit comments