lib/preexec: the last remnants of the `$OSTYPE` have been swept away
- Use a POSIX-compliant/portable extended regular expression to match on word-boundaries, rather than guessing which regex library `bash` was linked against. See https://stackoverflow.com/a/12696899/555333 for explanation and code suggestion.pull/2073/head
parent
c1943192ce
commit
8246794a28
|
|
@ -37,26 +37,20 @@ function __check_preexec_conflict() {
|
||||||
_bash-it-array-contains-element "${f}" "${preexec_functions[@]}"
|
_bash-it-array-contains-element "${f}" "${preexec_functions[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_append_prompt_command {
|
function safe_append_prompt_command() {
|
||||||
local prompt_re f
|
local prompt_re prompt_er f
|
||||||
__bp_trim_whitespace f "${1?}"
|
|
||||||
|
|
||||||
if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then
|
if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
|
||||||
# We are using bash-preexec
|
# We are using bash-preexec
|
||||||
|
__bp_trim_whitespace f "${1?}"
|
||||||
if ! __check_precmd_conflict "${f}"; then
|
if ! __check_precmd_conflict "${f}"; then
|
||||||
precmd_functions+=("${f}")
|
precmd_functions+=("${f}")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Set OS dependent exact match regular expression
|
# Match on word-boundaries
|
||||||
if [[ ${OSTYPE} == darwin* ]]; then
|
prompt_re='(^|[^[:alnum:]_])'
|
||||||
# macOS
|
prompt_er='([^[:alnum:]_]|$)'
|
||||||
prompt_re="[[:<:]]${1}[[:>:]]"
|
if [[ ${PROMPT_COMMAND} =~ ${prompt_re}"${1}"${prompt_er} ]]; then
|
||||||
else
|
|
||||||
# Linux, FreeBSD, etc.
|
|
||||||
prompt_re="\<${1}\>"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
|
|
||||||
return
|
return
|
||||||
elif [[ -z ${PROMPT_COMMAND} ]]; then
|
elif [[ -z ${PROMPT_COMMAND} ]]; then
|
||||||
PROMPT_COMMAND="${1}"
|
PROMPT_COMMAND="${1}"
|
||||||
|
|
@ -66,12 +60,12 @@ function safe_append_prompt_command {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function safe_append_preexec {
|
function safe_append_preexec() {
|
||||||
local prompt_re f
|
local prompt_re f
|
||||||
__bp_trim_whitespace f "${1?}"
|
|
||||||
|
|
||||||
if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then
|
if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
|
||||||
# We are using bash-preexec
|
# We are using bash-preexec
|
||||||
|
__bp_trim_whitespace f "${1?}"
|
||||||
if ! __check_preexec_conflict "${f}"; then
|
if ! __check_preexec_conflict "${f}"; then
|
||||||
preexec_functions+=("${f}")
|
preexec_functions+=("${f}")
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue