Skip to content

Commit

Permalink
fix: replace \s with [[:space:]] for POSIX sed/awk
Browse files Browse the repository at this point in the history
\s and \S are GNU extensions.  We need to replace them with
[[:space:]] and [^[:space:]], respectively, in sed.  Some awk
implementations do not support the POSIX character classes of the form
[[:space:]], so \s in awk needs to be replaced with the literal space
and tab, $'[ \t]'.
  • Loading branch information
akinomyoga committed Nov 28, 2023
1 parent d60c530 commit 1989ba9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion completions/_mock
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _comp_cmd_mock()
# This would actually depend on what the target root
# can be used to build for...
_comp_compgen_split -- "$(command rpm --showrc | command sed -ne \
's/^\s*compatible\s\s*archs\s*:\s*\(.*\)/\1/i p')"
's/^[[:space:]]*compatible[[:space:]]\{1,\}archs[[:space:]]*:[[:space:]]*\(.*\)/\1/i p')"
return
;;
--enable-plugin | --disable-plugin)
Expand Down
2 changes: 1 addition & 1 deletion completions/_yum
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _comp_cmd_yum__compgen_repolist()
# Drop first ("repo id repo name") and last ("repolist: ...") rows
_comp_compgen_split -- "$(
yum --noplugins -C repolist "$1" 2>/dev/null |
command sed -ne '/^repo\s\s*id/d' -e '/^repolist:/d' \
command sed -ne '/^repo[[:space:]]\{1,\}id/d' -e '/^repolist:/d' \
-e 's/[[:space:]].*//p'
)"
}
Expand Down
2 changes: 1 addition & 1 deletion completions/chronyc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ _comp_cmd_chronyc__command_args()
{
local -a args
_comp_split args "$("$1" help 2>/dev/null |
_comp_awk '/^'"$prev"'\s[^ []/ { gsub("\\|", " ", $2); print $2 }')"
_comp_awk '/^'"$prev"'[ \t][^ []/ { gsub("\\|", " ", $2); print $2 }')"
case $args in
\<address\>) _comp_compgen_known_hosts -- "$cur" ;;
\<*) ;;
Expand Down
6 changes: 3 additions & 3 deletions completions/puppet
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _comp_cmd_puppet__certs()
if [[ $1 == --all ]]; then
cert_list=$(
$puppetca --list --all |
command sed -e 's/^[+-]\{0,1\}\s*\(\S\{1,\}\)\s\{1,\}.*$/\1/'
command sed -e 's/^[+-]\{0,1\}[[:space:]]*\([^[:space:]]\{1,\}\)[[:space:]]\{1,\}.*$/\1/'
)
else
cert_list=$("$puppetca" --list)
Expand All @@ -35,7 +35,7 @@ _comp_cmd_puppet__certs()
_comp_cmd_puppet__types()
{
puppet_types=$(
puppet describe --list | command sed -e 's/^\(\S\{1,\}\).*$/\1/'
puppet describe --list | command sed -e 's/^\([^[:space:]]\{1,\}\).*$/\1/'
)
_comp_compgen -a -- -W "$puppet_types"
}
Expand All @@ -47,7 +47,7 @@ _comp_cmd_puppet__references()
puppetdoc=puppetdoc

puppet_doc_list=$(
$puppetdoc --list | command sed -e 's/^\(\S\{1,\}\).*$/\1/'
$puppetdoc --list | command sed -e 's/^\([^[:space:]]\{1,\}\).*$/\1/'
)
_comp_compgen -a -- -W "$puppet_doc_list"
}
Expand Down
2 changes: 1 addition & 1 deletion completions/rpm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _comp_cmd_rpm__macros()
_comp_cmd_rpm__buildarchs()
{
_comp_compgen_split -- "$("${1:-rpm}" --showrc | command sed -ne \
's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p')"
's/^[[:space:]]*compatible[[:space:]]\{1,\}build[[:space:]]\{1,\}archs[[:space:]]*:[[:space:]]*\(.*\)/\1/ p')"
}

# shellcheck disable=SC2120
Expand Down

0 comments on commit 1989ba9

Please sign in to comment.