Use [:blank:] when appropriate
This commit is contained in:
parent
30540f0bbf
commit
31ad7d7c28
1 changed files with 6 additions and 6 deletions
12
bash-abbr
12
bash-abbr
|
|
@ -119,7 +119,7 @@ _control_op () {
|
|||
_bg_proc_or_and_and='[^&;]&&?' \
|
||||
_pipe_or_or_or='[^&|;]\|\|?' \
|
||||
_semicolon_or_case_operators='[^;|];;?&?' \
|
||||
_opening_paren='(^|[^[:alnum:]])\('
|
||||
_opening_paren='(^|[^[:alnum:]])\('
|
||||
declare _control_op="^"
|
||||
_control_op+="|$_newline"
|
||||
_control_op+="|$_bg_proc_or_and_and"
|
||||
|
|
@ -140,7 +140,7 @@ _redir_or_assign_word () {
|
|||
_redir_or_append_out_and_err='(&)(>>?)' \
|
||||
_heredoc_herestring_in_out_etc='>>?|<(>|<(-?|<))?' \
|
||||
_identifier_equals='[[:alpha:]_][[:alnum:]]*=' \
|
||||
_simple_unquoted_word='[^[:space:]<>&;()|'\''"`$]+' \
|
||||
_simple_unquoted_word='[^[:blank:]<>&;()|'\''"`$]+' \
|
||||
_double_quoted_string='\$?"([^"]|\\")*"' \
|
||||
_single_quoted_string="\\\$?'[^']*'" \
|
||||
_backtick_string='`([^`]|\\`)*`' \
|
||||
|
|
@ -164,17 +164,17 @@ _redir_or_assign_word () {
|
|||
_close_redirection="($_varredir_or_number)($_redir_in_or_out)($_close_or_move_fd)" \
|
||||
_generic_redirection="($_redir_or_append_out_and_err|($_varredir_or_number)($_heredoc_herestring_in_out_etc))"
|
||||
# shellcheck disable=SC1087
|
||||
declare -r _word_redirection_or_assignment="($_generic_redirection[[:space:]]*|$_identifier_equals)($_word)"
|
||||
declare -r _word_redirection_or_assignment="($_generic_redirection[[:blank:]]*|$_identifier_equals)($_word)"
|
||||
printf %s "$_close_redirection|$_word_redirection_or_assignment"
|
||||
unset -f _redir_or_assign_word
|
||||
}
|
||||
# shellcheck disable=SC2155
|
||||
declare -r _redir_or_assign_word="$(_redir_or_assign_word)" # TODO use bash 5.3 `${}` command substitution syntax to avoid subshells
|
||||
|
||||
declare -r is_first_word_prefix="($_control_op)[[:space:]]*((($_redir_or_assign_word)[[:space:]])*)"
|
||||
declare -r is_first_word_prefix="($_control_op)[[:blank:]]*((($_redir_or_assign_word)[[:blank:]])*)"
|
||||
# If the regex leads to problems/performance issues, you may try this simpler regex
|
||||
# that does no redirection/assignment word checking:
|
||||
# declare -r is_first_word_prefix="($_control_op)[[:space:]]*"
|
||||
# declare -r is_first_word_prefix="($_control_op)[[:blank:]]*"
|
||||
|
||||
unset -v _control_op
|
||||
|
||||
|
|
@ -259,7 +259,7 @@ _try_abbrev_internal () {
|
|||
|
||||
# Recursively expand replacement if we haven't expanded it already
|
||||
declare tmp=" $replacement" # Prepend space, makes the logic easier
|
||||
[[ $tmp =~ ^([[:space:]]*$is_first_word_prefix) ]] && tmp=${tmp#"${BASH_REMATCH[1]}"} # Strip matching prefix
|
||||
[[ $tmp =~ ^([[:blank:]]*$is_first_word_prefix) ]] && tmp=${tmp#"${BASH_REMATCH[1]}"} # Strip matching prefix
|
||||
declare -r word_to_expand=${tmp%%[<>&;()|[:space:]]*}
|
||||
if [[ -z ${_expanded_aliases[$word_to_expand]-} ]]; then
|
||||
declare -r point_for_replacement=$((${#BASH_REMATCH[1]}+${#word_to_expand}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue