Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions completions-core/apache2ctl.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ _comp_cmd_apache2ctl()
_comp_initialize -- "$@" || return

local APWORDS
APWORDS=$("$1" 2>&1 >/dev/null | _comp_awk 'NR<2 { print $3; exit }' |
tr "|" " ")
APWORDS=$("$1" 2>&1 >/dev/null | _comp_awk 'NR < 2 { print $3; exit }')

_comp_compgen -- -W "$APWORDS"
_comp_compgen_split -F $' \t\n|' -- "$APWORDS"
} &&
complete -F _comp_cmd_apache2ctl apache2ctl

Expand Down
2 changes: 1 addition & 1 deletion completions-core/bk.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _comp_cmd_bk()
_comp_initialize -- "$@" || return

local BKCMDS=$(bk help topics 2>/dev/null |
_comp_awk '/^ bk/ { print $2 }' | xargs printf '%s ')
_comp_awk '/^ bk/ { print $2 }')

_comp_compgen -- -W "$BKCMDS"
_comp_compgen -a filedir
Expand Down
2 changes: 1 addition & 1 deletion completions-core/gcc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _comp_cmd_gcc()
local cc=$("$1" -print-prog-name=cc1 2>/dev/null)
[[ $cc ]] || return
_comp_compgen_split -- "$("$cc" --help 2>/dev/null | tr '\t' ' ' |
command sed -e '/^ *-/!d' -e 's/ *-\([^][ <>]*\).*/-\1/')"
command sed -n 's/^ \{1,\}\(-[^][ <>]*\).*/\1/p')"
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
else
_comp_compgen_filedir
Expand Down
17 changes: 8 additions & 9 deletions completions-core/tshark.bash
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ _comp_cmd_tshark()
if [[ $cur == *:* ]]; then
_comp_compgen -c "${cur#*:}" filedir
else
[[ -v _comp_cmd_tshark__prefs ]] ||
_comp_cmd_tshark__prefs=$("$1" -G defaultprefs 2>/dev/null | command sed -ne 's/^#\{0,1\}\([a-z0-9_.-]\{1,\}:\).*/\1/p' |
tr '\n' ' ')
: ${prefix:=}
_comp_compgen -P "$prefix" -- -W "$_comp_cmd_tshark__prefs"
[[ -v _comp_cmd_tshark__mut_prefs ]] ||
_comp_cmd_tshark__mut_prefs=$("$1" -G defaultprefs 2>/dev/null |
command sed -ne 's/^#\{0,1\}\([a-z0-9_.-]\{1,\}:\).*/\1/p')
_comp_compgen -P "$prefix" -- -W "$_comp_cmd_tshark__mut_prefs"
[[ ${COMPREPLY-} == *: ]] && compopt -o nospace
fi
return
Expand Down Expand Up @@ -71,10 +70,10 @@ _comp_cmd_tshark()
return
;;
-*O)
[[ -v _comp_cmd_tshark__protocols ]] ||
_comp_cmd_tshark__protocols=$("$1" -G protocols 2>/dev/null |
cut -f 3 | tr '\n' ' ')
_comp_delimited , -W "$_comp_cmd_tshark__protocols"
[[ -v _comp_cmd_tshark__mut_protocols ]] ||
_comp_cmd_tshark__mut_protocols=$("$1" -G protocols 2>/dev/null |
cut -f 3)
_comp_delimited , -W "$_comp_cmd_tshark__mut_protocols"
return
;;
-*T)
Expand Down
3 changes: 2 additions & 1 deletion completions-core/update-rc.d.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ _comp_cmd_update_rc_d()
options=(-f -n)

if [[ $cword -eq 1 || $prev == -* ]]; then
local IFS='|'
_comp_compgen -- -W '"${options[@]}" ${services[@]+"${services[@]}"}' \
-X '$(tr " " "|" <<<${words[@]})'
-X "@(${words[*]}))"
elif ((${#services[@]})) && [[ $prev == ?($(tr " " "|" <<<"${services[*]}")) ]]; then
_comp_compgen -- -W 'remove defaults start stop'
elif [[ $prev == defaults && $cur == [0-9] ]]; then
Expand Down
4 changes: 2 additions & 2 deletions completions-fallback/modules.bash
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ _comp_cmd_module()
# First parameter on line -- we expect it to be a mode selection

local options
options=$(module help 2>&1 | command grep -E '^[[:space:]]*\+' |
_comp_awk '{print $2}' | command sed -e 's/|/ /g' | sort)
options=$(module help 2>&1 | _comp_awk '/^[[:space:]]*\+/ {
$0 = $2; gsub(/\|/, " "); print }' | sort)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a nagging feeling that there is an awk implementation in existence that does not support gsub, but I can't find it right now and gsub is in POSIX at least down to 2008, so maybe it's all good.

There is one gsub use in the tree in chronyc, but that could be fine if we assume chronyc is Linux specific.

Copy link
Collaborator Author

@akinomyoga akinomyoga Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that Solaris awk? Solaris <= 11.3 awk indeed doesn't have gsub:

$ awk 'gsub(/a/, "b")' <<< "aaazzz"
awk: syntax error near line 1
awk: bailing out near line 1

We use /usr/xpg4/bin/awk (which has gsub) in Solaris through the wrapper _comp_awk, so the problem doesn't happen in Solaris.

I don't have AIX, NetBSD, and OpenBSD, but online manuals seem to suggest that their awk has gsub.


_comp_compgen -- -W "$options"

Expand Down
1 change: 0 additions & 1 deletion test/t/test_tshark.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest


@pytest.mark.bashcomp(ignore_env=r"^\+_comp_cmd_tshark__pr(ef|otocol)s=")
class TestTshark:
@pytest.mark.complete("tshark -", require_cmd=True)
def test_1(self, completion):
Expand Down