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
John D Pell 2022-02-11 22:42:24 -08:00
parent c1943192ce
commit 8246794a28
1 changed files with 11 additions and 17 deletions

View File

@ -37,26 +37,20 @@ function __check_preexec_conflict() {
_bash-it-array-contains-element "${f}" "${preexec_functions[@]}"
}
function safe_append_prompt_command {
local prompt_re f
__bp_trim_whitespace f "${1?}"
function safe_append_prompt_command() {
local prompt_re prompt_er f
if [ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]; then
if [[ "${bash_preexec_imported:-${__bp_imported:-missing}}" == "defined" ]]; then
# We are using bash-preexec
__bp_trim_whitespace f "${1?}"
if ! __check_precmd_conflict "${f}"; then
precmd_functions+=("${f}")
fi
else
# Set OS dependent exact match regular expression
if [[ ${OSTYPE} == darwin* ]]; then
# macOS
prompt_re="[[:<:]]${1}[[:>:]]"
else
# Linux, FreeBSD, etc.
prompt_re="\<${1}\>"
fi
if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then
# Match on word-boundaries
prompt_re='(^|[^[:alnum:]_])'
prompt_er='([^[:alnum:]_]|$)'
if [[ ${PROMPT_COMMAND} =~ ${prompt_re}"${1}"${prompt_er} ]]; then
return
elif [[ -z ${PROMPT_COMMAND} ]]; then
PROMPT_COMMAND="${1}"
@ -66,12 +60,12 @@ function safe_append_prompt_command {
fi
}
function safe_append_preexec {
function safe_append_preexec() {
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
__bp_trim_whitespace f "${1?}"
if ! __check_preexec_conflict "${f}"; then
preexec_functions+=("${f}")
fi