Skip to content

Commit 791f56c

Browse files
committed
fix(portinstall): use awk and _comp_compgen to filter completions
1 parent 434eb08 commit 791f56c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

completions/portinstall

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,20 @@ _comp_cmd_portinstall()
77

88
[[ $prev == -l || $prev == -L || $prev == -o ]] && return
99

10-
local portsdir indexfile
11-
local -a COMPREPLY2
12-
13-
portsdir=${PORTSDIR:-/usr/ports}/
10+
local -x portsdir=${PORTSDIR:-/usr/ports}/
1411

1512
# First try INDEX-5
16-
indexfile=$portsdir/INDEX-5
13+
local indexfile=$portsdir/INDEX-5
1714
# Then INDEX if INDEX-5 does not exist or system is not FreeBSD 5.x
1815
[[ ${OSTYPE%.*} == freebsd5 && -f $indexfile ]] ||
1916
indexfile=$portsdir/INDEX
2017
[[ -f $indexfile && -r $indexfile ]] || return
2118

22-
COMPREPLY=($(command grep -E "^$cur" 2>/dev/null <"$indexfile" |
23-
cut -d'|' -f1))
24-
COMPREPLY2=($(command grep -E "^[^\|]+\|$portsdir$cur" 2>/dev/null \
25-
<"$indexfile" | cut -d'|' -f2))
26-
COMPREPLY2=(${COMPREPLY2[@]#$portsdir})
27-
COMPREPLY+=("${COMPREPLY2[@]}")
19+
_comp_compgen_split -l -- "$(awk -F '|' '
20+
BEGIN { portsdir = ENVIRON["portsdir"]; len = length(portsdir) }
21+
{ print $1 }
22+
substr($2, 1, len) == portsdir { print substr($2, len + 1) }
23+
' "$indexfile")"
2824

2925
} &&
3026
complete -F _comp_cmd_portinstall -o dirnames portinstall

0 commit comments

Comments
 (0)