lib/preexec: trim whitespace
Alsö, use `_bash-it-array-contains-element()`pull/2003/head
parent
7770e8cbb9
commit
ae8c9c08a3
|
|
@ -27,32 +27,25 @@ __bp_install_after_session_init
|
||||||
|
|
||||||
## Helper functions
|
## Helper functions
|
||||||
function __check_precmd_conflict() {
|
function __check_precmd_conflict() {
|
||||||
local f # TODO: trim whitespace like preexec does
|
local f
|
||||||
for f in "${precmd_functions[@]}"; do
|
__bp_trim_whitespace f "${1?}"
|
||||||
if [[ "${f}" == "${1}" ]]; then
|
! _bash-it-array-contains-element "${f}" "${precmd_functions[@]}"
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function __check_preexec_conflict() {
|
function __check_preexec_conflict() {
|
||||||
local f # TODO: trim whitespace like preexec does
|
local f
|
||||||
for f in "${preexec_functions[@]}"; do
|
__bp_trim_whitespace f "${1?}"
|
||||||
if [[ "${f}" == "${1}" ]]; then
|
! _bash-it-array-contains-element "${f}" "${preexec_functions[@]}"
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_append_prompt_command {
|
function safe_append_prompt_command {
|
||||||
local prompt_re
|
local prompt_re f
|
||||||
|
__bp_trim_whitespace f "${1?}"
|
||||||
|
|
||||||
if [ "${__bp_imported:-missing}" == "defined" ]; then
|
if [ "${__bp_imported:-missing}" == "defined" ]; then
|
||||||
# We are using bash-preexec
|
# We are using bash-preexec
|
||||||
if ! __check_precmd_conflict "${1}"; then
|
if ! __check_precmd_conflict "${f}"; then
|
||||||
precmd_functions+=("${1}")
|
precmd_functions+=("${f}")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Set OS dependent exact match regular expression
|
# Set OS dependent exact match regular expression
|
||||||
|
|
@ -75,12 +68,13 @@ function safe_append_prompt_command {
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_append_preexec {
|
function safe_append_preexec {
|
||||||
local prompt_re
|
local prompt_re f
|
||||||
|
__bp_trim_whitespace f "${1?}"
|
||||||
|
|
||||||
if [ "${__bp_imported:-missing}" == "defined" ]; then
|
if [ "${__bp_imported:-missing}" == "defined" ]; then
|
||||||
# We are using bash-preexec
|
# We are using bash-preexec
|
||||||
if ! __check_preexec_conflict "${1}"; then
|
if ! __check_preexec_conflict "${f}"; then
|
||||||
preexec_functions+=("${1}")
|
preexec_functions+=("${f}")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
_log_error "${FUNCNAME[0]}: can't append to preexec hook because _bash-preexec.sh_ hasn't been loaded"
|
_log_error "${FUNCNAME[0]}: can't append to preexec hook because _bash-preexec.sh_ hasn't been loaded"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue