Use [:blank:] when appropriate

This commit is contained in:
tsi 2025-12-25 20:48:22 +01:00
parent 30540f0bbf
commit 31ad7d7c28
No known key found for this signature in database

View file

@ -140,7 +140,7 @@ _redir_or_assign_word () {
_redir_or_append_out_and_err='(&)(>>?)' \ _redir_or_append_out_and_err='(&)(>>?)' \
_heredoc_herestring_in_out_etc='>>?|<(>|<(-?|<))?' \ _heredoc_herestring_in_out_etc='>>?|<(>|<(-?|<))?' \
_identifier_equals='[[:alpha:]_][[:alnum:]]*=' \ _identifier_equals='[[:alpha:]_][[:alnum:]]*=' \
_simple_unquoted_word='[^[:space:]<>&;()|'\''"`$]+' \ _simple_unquoted_word='[^[:blank:]<>&;()|'\''"`$]+' \
_double_quoted_string='\$?"([^"]|\\")*"' \ _double_quoted_string='\$?"([^"]|\\")*"' \
_single_quoted_string="\\\$?'[^']*'" \ _single_quoted_string="\\\$?'[^']*'" \
_backtick_string='`([^`]|\\`)*`' \ _backtick_string='`([^`]|\\`)*`' \
@ -164,17 +164,17 @@ _redir_or_assign_word () {
_close_redirection="($_varredir_or_number)($_redir_in_or_out)($_close_or_move_fd)" \ _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))" _generic_redirection="($_redir_or_append_out_and_err|($_varredir_or_number)($_heredoc_herestring_in_out_etc))"
# shellcheck disable=SC1087 # 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" printf %s "$_close_redirection|$_word_redirection_or_assignment"
unset -f _redir_or_assign_word unset -f _redir_or_assign_word
} }
# shellcheck disable=SC2155 # 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 _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 # If the regex leads to problems/performance issues, you may try this simpler regex
# that does no redirection/assignment word checking: # 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 unset -v _control_op
@ -259,7 +259,7 @@ _try_abbrev_internal () {
# Recursively expand replacement if we haven't expanded it already # Recursively expand replacement if we haven't expanded it already
declare tmp=" $replacement" # Prepend space, makes the logic easier 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:]]*} declare -r word_to_expand=${tmp%%[<>&;()|[:space:]]*}
if [[ -z ${_expanded_aliases[$word_to_expand]-} ]]; then if [[ -z ${_expanded_aliases[$word_to_expand]-} ]]; then
declare -r point_for_replacement=$((${#BASH_REMATCH[1]}+${#word_to_expand})) declare -r point_for_replacement=$((${#BASH_REMATCH[1]}+${#word_to_expand}))