Use _init_completion() in completions/a*.

This commit is contained in:
Ville Skyttä 2011-04-20 14:18:27 +03:00
parent ab29cef65a
commit faf8ad159e
10 changed files with 51 additions and 62 deletions

View File

@ -4,14 +4,12 @@ have abook || return
_abook() _abook()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
# abook only takes options, tabbing after command name adds a single # abook only takes options, tabbing after command name adds a single
# dash (bash4) # dash (bash4)
[[ ${BASH_VERSINFO[0]} -ge 4 && $COMP_CWORD -eq 1 && -z "$cur" ]] && [[ ${BASH_VERSINFO[0]} -ge 4 && $cword -eq 1 && -z "$cur" ]] &&
{ {
compopt -o nospace compopt -o nospace
COMPREPLY=( "-" ) COMPREPLY=( "-" )

View File

@ -4,10 +4,8 @@ have ant || return
_ant() _ant()
{ {
local cur prev buildfile i local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-buildfile|-file|-f) -buildfile|-file|-f)
@ -40,10 +38,10 @@ _ant()
else else
# available targets completion # available targets completion
# find which buildfile to use # find which buildfile to use
buildfile=build.xml local buildfile=build.xml i
for (( i=1; i < COMP_CWORD; i++ )); do for (( i=1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == -@(?(build)file|f) ]]; then if [[ "${words[i]}" == -@(?(build)file|f) ]]; then
buildfile=${COMP_WORDS[i+1]} buildfile=${words[i+1]}
break break
fi fi
done done

View File

@ -4,11 +4,10 @@ have apache2ctl || return
_apache2ctl() _apache2ctl()
{ {
local APWORDS cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
local APWORDS
APWORDS=$(apache2ctl 2>&1 >/dev/null | awk 'NR<2 { print $3; exit }' | \ APWORDS=$(apache2ctl 2>&1 >/dev/null | awk 'NR<2 { print $3; exit }' | \
tr "|" " ") tr "|" " ")

View File

@ -3,14 +3,13 @@
have apt-get && have apt-get &&
_apt_get() _apt_get()
{ {
local cur prev special i local cur prev words cword
_init_completion || return
COMPREPLY=() local special i
_get_comp_words_by_ref cur prev for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == @(install|remove|autoremove|purge|source|build-dep) ]]; then
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do special=${words[i]}
if [[ ${COMP_WORDS[i]} == @(install|remove|autoremove|purge|source|build-dep) ]]; then
special=${COMP_WORDS[i]}
fi fi
done done
@ -78,15 +77,14 @@ complete -F _apt_get apt-get
have apt-cache && have apt-cache &&
_apt_cache() _apt_cache()
{ {
local cur prev special i local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
local special i
if [ "$cur" != show ]; then if [ "$cur" != show ]; then
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${COMP_WORDS[i]} == @(add|depends|dotty|madison|policy|rdepends|show?(pkg|src|)) ]]; then if [[ ${words[i]} == @(add|depends|dotty|madison|policy|rdepends|show?(pkg|src|)) ]]; then
special=${COMP_WORDS[i]} special=${words[i]}
fi fi
done done
fi fi

View File

@ -4,14 +4,13 @@ have apt-build || return
_apt_build() _apt_build()
{ {
local cur prev special i local cur prev words cword
_init_completion || return
COMPREPLY=() local special i
_get_comp_words_by_ref cur prev for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == @(install|remove|source|info|clean) ]]; then
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do special=${words[i]}
if [[ ${COMP_WORDS[i]} == @(install|remove|source|info|clean) ]]; then
special=${COMP_WORDS[i]}
fi fi
done done

View File

@ -17,11 +17,10 @@ _comp_dpkg_hold_packages()
_aptitude() _aptitude()
{ {
local cur dashoptions prev special i local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
local dashoptions
dashoptions='-S -u -i -h --help --version -s --simulate -d \ dashoptions='-S -u -i -h --help --version -s --simulate -d \
--download-only -P --prompt -y --assume-yes -F \ --download-only -P --prompt -y --assume-yes -F \
--display-format -O --sort -w --width -f -r -g \ --display-format -O --sort -w --width -f -r -g \
@ -29,13 +28,14 @@ _aptitude()
--target-release -V --show-versions -D --show-deps\ --target-release -V --show-versions -D --show-deps\
-Z -v --verbose --purge-unused --schedule-only' -Z -v --verbose --purge-unused --schedule-only'
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do local special i
if [[ ${COMP_WORDS[i]} == @(@(|re)install|@(|un)hold|@(|un)markauto|@(dist|full)-upgrade|download|show|forbid-version|purge|remove|changelog|why@(|-not)|keep@(|-all)|build-dep|@(add|remove)-user-tag) ]]; then for (( i=0; i < ${#words[@]}-1; i++ )); do
special=${COMP_WORDS[i]} if [[ ${words[i]} == @(@(|re)install|@(|un)hold|@(|un)markauto|@(dist|full)-upgrade|download|show|forbid-version|purge|remove|changelog|why@(|-not)|keep@(|-all)|build-dep|@(add|remove)-user-tag) ]]; then
special=${words[i]}
fi fi
#exclude some mutually exclusive options #exclude some mutually exclusive options
[[ ${COMP_WORDS[i]} == '-u' ]] && dashoptions=${dashoptions/-i} [[ ${words[i]} == '-u' ]] && dashoptions=${dashoptions/-i}
[[ ${COMP_WORDS[i]} == '-i' ]] && dashoptions=${dashoptions/-u} [[ ${words[i]} == '-i' ]] && dashoptions=${dashoptions/-u}
done done
if [[ -n "$special" ]]; then if [[ -n "$special" ]]; then

View File

@ -17,11 +17,10 @@ _aspell_dictionary()
_aspell() _aspell()
{ {
local cur prev split=false local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
local split=false
_split_longopt && split=true _split_longopt && split=true
case $prev in case $prev in

View File

@ -3,10 +3,10 @@
have autoconf && have autoconf &&
_autoconf() _autoconf()
{ {
COMPREPLY=() local cur prev words cword
local cur prev split=false _init_completion || return
_get_comp_words_by_ref cur prev
local split=false
_split_longopt && split=true _split_longopt && split=true
case "$prev" in case "$prev" in

View File

@ -3,10 +3,10 @@
have automake && have automake &&
_automake() _automake()
{ {
COMPREPLY=() local cur prev words cword
local cur prev split=false _init_completion || return
_get_comp_words_by_ref cur prev
local split=false
_split_longopt && split=true _split_longopt && split=true
case "$prev" in case "$prev" in

View File

@ -4,10 +4,8 @@ have autorpm || return
_autorpm() _autorpm()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
COMPREPLY=( $( compgen -W '--notty --debug --help --version auto add \ COMPREPLY=( $( compgen -W '--notty --debug --help --version auto add \
fullinfo info help install list remove set' -- "$cur" ) ) fullinfo info help install list remove set' -- "$cur" ) )