diff options
Diffstat (limited to 'completions/portinstall')
-rw-r--r-- | completions/portinstall | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/completions/portinstall b/completions/portinstall index 8033740..dc1a933 100644 --- a/completions/portinstall +++ b/completions/portinstall @@ -1,31 +1,28 @@ # bash completion for FreeBSD portinstall -*- shell-script -*- -_portinstall() +_comp_cmd_portinstall() { - local cur prev words cword - _init_completion || return + local cur prev words cword comp_args + _comp_initialize -- "$@" || return - local portsdir indexfile - local -a COMPREPLY2 + [[ $prev == -l || $prev == -L || $prev == -o ]] && return - portsdir=${PORTSDIR:-/usr/ports}/ + local -x portsdir=${PORTSDIR:-/usr/ports}/ # First try INDEX-5 - indexfile=$portsdir/INDEX-5 + local indexfile=$portsdir/INDEX-5 # Then INDEX if INDEX-5 does not exist or system is not FreeBSD 5.x [[ ${OSTYPE%.*} == freebsd5 && -f $indexfile ]] || indexfile=$portsdir/INDEX + [[ -f $indexfile && -r $indexfile ]] || return - [[ $prev == -l || $prev == -L || $prev == -o ]] && return - - COMPREPLY=($(command grep -E "^$cur" 2>/dev/null <$indexfile | - cut -d'|' -f1)) - COMPREPLY2=($(command grep -E "^[^\|]+\|$portsdir$cur" 2>/dev/null \ - <$indexfile | cut -d'|' -f2)) - COMPREPLY2=(${COMPREPLY2[@]#$portsdir}) - COMPREPLY+=("${COMPREPLY2[@]}") + _comp_compgen_split -l -- "$(_comp_awk -F '|' ' + BEGIN { portsdir = ENVIRON["portsdir"]; len = length(portsdir) } + { print $1 } + substr($2, 1, len) == portsdir { print substr($2, len + 1) } + ' "$indexfile")" } && - complete -F _portinstall -o dirnames portinstall + complete -F _comp_cmd_portinstall -o dirnames portinstall # ex: filetype=sh |