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