Use _init_completion() in completions/[q-z]*.

This commit is contained in:
Ville Skyttä 2011-04-21 11:04:51 +03:00
parent e3ca91b986
commit 8048917968
58 changed files with 337 additions and 458 deletions

View File

@ -4,13 +4,11 @@ have qdbus || have dcop || return
_qdbus() _qdbus()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=() [ -n "$cur" ] && unset words[${#words[@]}-1]
_get_comp_words_by_ref cur COMPREPLY=( $( compgen -W '$( command ${words[@]} 2>/dev/null | \
[ -n "$cur" ] && unset COMP_WORDS[${#COMP_WORDS[@]}-1]
COMPREPLY=( $( compgen -W '$( command ${COMP_WORDS[@]} 2>/dev/null | \
sed s/\(.*\)// )' -- "$cur" ) ) sed s/\(.*\)// )' -- "$cur" ) )
} && } &&
complete -F _qdbus qdbus dcop complete -F _qdbus qdbus dcop

View File

@ -4,10 +4,8 @@ have qemu || return
_qemu() _qemu()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-fd[ab]|-hd[abcd]|-cdrom|-option-rom|-kernel|-initrd|-bootp|-pidfile| \ -fd[ab]|-hd[abcd]|-cdrom|-option-rom|-kernel|-initrd|-bootp|-pidfile| \

View File

@ -7,8 +7,8 @@ _user_or_group()
local i local i
# complete on groups if -g was given # complete on groups if -g was given
for (( i=1; i < COMP_CWORD; i++ )); do for (( i=1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == -g ]]; then if [[ "${words[i]}" == -g ]]; then
COMPREPLY=( $( compgen -g -- "$cur" ) ) COMPREPLY=( $( compgen -g -- "$cur" ) )
return 0 return 0
fi fi
@ -33,11 +33,10 @@ _filesystems()
_quota() _quota()
{ {
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
@ -62,11 +61,10 @@ complete -F _quota -o default quota
_setquota() _setquota()
{ {
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
@ -101,11 +99,10 @@ complete -F _setquota -o default setquota
_edquota() _edquota()
{ {
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
@ -133,11 +130,10 @@ complete -F _edquota -o default edquota
_quotacheck() _quotacheck()
{ {
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
@ -162,11 +158,10 @@ complete -F _quotacheck -o default quotacheck
_repquota() _repquota()
{ {
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
@ -191,11 +186,10 @@ complete -F _repquota -o default repquota
_quotaon() _quotaon()
{ {
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
@ -218,11 +212,10 @@ complete -F _quotaon -o default quotaon
_quotaoff() _quotaoff()
{ {
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

@ -4,10 +4,10 @@ have rcs || return
_rcs() _rcs()
{ {
local cur prev file dir i local cur prev words cword
_init_completion || return
COMPREPLY=() local file dir i
_get_comp_words_by_ref cur prev
file=${cur##*/} file=${cur##*/}
dir=${cur%/*} dir=${cur%/*}

View File

@ -4,10 +4,8 @@ have rdesktop || return
_rdesktop() _rdesktop()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-k) -k)

View File

@ -3,10 +3,8 @@
have reportbug && have reportbug &&
_reportbug() _reportbug()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-f|--filename|-i|--include|--mta|-o|--output) -f|--filename|-i|--include|--mta|-o|--output)
@ -19,8 +17,8 @@ _reportbug()
return 0 return 0
;; ;;
-e|--editor|--mua) -e|--editor|--mua)
COMP_WORDS=(COMP_WORDS[0] "$cur") words=(words[0] "$cur")
COMP_CWORD=1 cword=1
_command _command
return 0 return 0
;; ;;
@ -89,11 +87,10 @@ complete -F _reportbug reportbug
have querybts && have querybts &&
_querybts() _querybts()
{ {
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

@ -4,10 +4,8 @@ have reptyr || return
_reptyr() _reptyr()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-l) -l)

View File

@ -4,10 +4,8 @@ have resolvconf || return
_resolvconf() _resolvconf()
{ {
local cur command local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-a|-d) -a|-d)

View File

@ -4,15 +4,13 @@ have rfkill || return
_rfkill() _rfkill()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--version' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--version' -- "$cur" ) )
else else
case $COMP_CWORD in case $cword in
1) 1)
COMPREPLY=( $( compgen -W "help event list block unblock" \ COMPREPLY=( $( compgen -W "help event list block unblock" \
-- "$cur" ) ) -- "$cur" ) )

View File

@ -35,11 +35,11 @@ ri_get_methods()
# needs at least Ruby 1.8.0 in order to use -W0 # needs at least Ruby 1.8.0 in order to use -W0
_ri() _ri()
{ {
local cur class method prefix ri_path ri_version separator IFS local cur prev words cword
local -a classes _init_completion || return
COMPREPLY=() local class method prefix ri_path ri_version separator IFS
_get_comp_words_by_ref cur local -a classes
ri_path=$(type -p ri) ri_path=$(type -p ri)
# which version of ri are we using? # which version of ri are we using?

View File

@ -7,9 +7,9 @@ _rpcdebug_flags()
local i module local i module
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do for (( i=0; i < ${#words[@]}; i++ )); do
if [[ ${COMP_WORDS[i]} == -m ]]; then if [[ ${words[i]} == -m ]]; then
module=${COMP_WORDS[i+1]} module=${words[i+1]}
fi fi
done done
@ -21,10 +21,8 @@ _rpcdebug_flags()
_rpcdebug() _rpcdebug()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-s) -s)

View File

@ -39,12 +39,10 @@ _rpm_macros()
# #
_rpm() _rpm()
{ {
local cur prev opts local cur prev words cword
_init_completion || return
COMPREPLY=() if [ $cword -eq 1 ]; then
_get_comp_words_by_ref cur prev
if [ $COMP_CWORD -eq 1 ]; then
# first parameter on line # first parameter on line
case $cur in case $cur in
--*) --*)
@ -117,10 +115,10 @@ _rpm()
esac esac
# options common to all modes # options common to all modes
opts="--define --eval --macros --nodigest --nosignature --rcfile \ local opts="--define --eval --macros --nodigest --nosignature --rcfile \
--quiet --pipe --verbose" --quiet --pipe --verbose"
case ${COMP_WORDS[1]} in case ${words[1]} in
-[iFU]*|--install|--freshen|--upgrade) -[iFU]*|--install|--freshen|--upgrade)
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --percent --force \ COMPREPLY=( $( compgen -W "$opts --percent --force \
@ -152,7 +150,7 @@ _rpm()
--list --obsoletes --pipe --provides --queryformat --rcfile --list --obsoletes --pipe --provides --queryformat --rcfile
--requires --scripts --suggests --triggers --xml" --requires --scripts --suggests --triggers --xml"
if [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then if [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
# -qf completion # -qf completion
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \ COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \
@ -160,10 +158,10 @@ _rpm()
else else
_filedir _filedir
fi fi
elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then
# -qg completion # -qg completion
_rpm_groups $1 _rpm_groups $1
elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then
# -qp; uninstalled package completion # -qp; uninstalled package completion
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \ COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \
@ -179,7 +177,7 @@ _rpm()
--package --pkgid --root --specfile --state --package --pkgid --root --specfile --state
--triggeredby --whatprovides --whatrequires" \ --triggeredby --whatprovides --whatrequires" \
-- "$cur" ) ) -- "$cur" ) )
elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then elif [[ ${words[@]} != *\ -@(*([^ -])a|-all )* ]]; then
_rpm_installed_packages $1 _rpm_installed_packages $1
fi fi
fi fi
@ -199,11 +197,11 @@ _rpm()
--nofiles --noscripts --nomd5 --querytags --specfile \ --nofiles --noscripts --nomd5 --querytags --specfile \
--whatrequires --whatprovides" -- "$cur" ) ) --whatrequires --whatprovides" -- "$cur" ) )
# check whether we're doing file completion # check whether we're doing file completion
elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then elif [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then
_filedir _filedir
elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then
_rpm_groups $1 _rpm_groups $1
elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then
_filedir '[rs]pm' _filedir '[rs]pm'
else else
_rpm_installed_packages $1 _rpm_installed_packages $1
@ -231,10 +229,10 @@ complete -F _rpm rpm
_rpmbuild() _rpmbuild()
{ {
COMPREPLY=() local cur prev words cword
local cur prev words split=false _init_completion || return
_get_comp_words_by_ref cur prev words
local split=false
_split_longopt && split=true _split_longopt && split=true
local rpm="${1%build*}" local rpm="${1%build*}"
@ -304,14 +302,10 @@ complete -F _rpmbuild rpmbuild rpmbuild-md5
have gendiff && have gendiff &&
_gendiff() _gendiff()
{ {
COMPREPLY=() local cur prev words cword
local cur prev cword _init_completion -o @(diff|patch) || return
_get_comp_words_by_ref cur prev cword
if [[ $cword -eq 1 ]]; then [[ $cword -eq 1 ]] && _filedir -d
_filedir -d
elif [[ $prev == *\> ]]; then
_filedir
fi
} && } &&
complete -F _gendiff gendiff complete -F _gendiff gendiff

View File

@ -4,10 +4,8 @@ have rpmcheck || return
_rpmcheck() _rpmcheck()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-base) -base)

View File

@ -4,8 +4,8 @@ have rrdtool || return
_rrdtool () _rrdtool ()
{ {
local cur local cur prev words cword
_get_comp_words_by_ref cur _init_completion || return
COMPREPLY=( $( compgen -W 'create update updatev graph dump restore last \ COMPREPLY=( $( compgen -W 'create update updatev graph dump restore last \
lastupdate first info fetch tune resize xport' -- "$cur" ) ) lastupdate first info fetch tune resize xport' -- "$cur" ) )

View File

@ -4,11 +4,10 @@ have rsync || return
_rsync() _rsync()
{ {
# TODO: _split_longopt local cur prev words cword
_init_completion -n : || return
COMPREPLY=() # TODO: _split_longopt
local cur prev
_get_comp_words_by_ref -n : cur prev
_expand || return 0 _expand || return 0
@ -65,9 +64,9 @@ _rsync()
if type _scp_remote_files &>/dev/null; then if type _scp_remote_files &>/dev/null; then
# find which remote shell is used # find which remote shell is used
local i shell=ssh local i shell=ssh
for (( i=1; i < COMP_CWORD; i++ )); do for (( i=1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then if [[ "${words[i]}" == -@(e|-rsh) ]]; then
shell=${COMP_WORDS[i+1]} shell=${words[i+1]}
break break
fi fi
done done

View File

@ -4,10 +4,10 @@ have rtcwake || return
_rtcwake() _rtcwake()
{ {
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

@ -30,11 +30,10 @@ _samba_debuglevel()
_smbclient() _smbclient()
{ {
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
@ -96,11 +95,10 @@ complete -F _smbclient smbclient
_smbget() _smbget()
{ {
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
@ -128,11 +126,10 @@ complete -F _smbget smbget
_smbcacls() _smbcacls()
{ {
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
@ -161,11 +158,10 @@ complete -F _smbcacls smbcacls
_smbcquotas() _smbcquotas()
{ {
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
@ -195,10 +191,8 @@ complete -F _smbcquotas smbcquotas
_smbpasswd() _smbpasswd()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-r) -r)
@ -228,10 +222,8 @@ complete -F _smbpasswd smbpasswd
_smbtar() _smbtar()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-r|-t) -r|-t)
@ -257,11 +249,10 @@ complete -F _smbtar smbtar
_smbtree() _smbtree()
{ {
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

@ -5,10 +5,8 @@ have sbcl || have sbcl-mt || return
_sbcl() _sbcl()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
# completing an option (may or may not be separated by a space) # completing an option (may or may not be separated by a space)
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then

View File

@ -11,9 +11,7 @@ _screen_sessions()
_screen() _screen()
{ {
local cur prev words cword local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev words cword
if ((cword > 2)); then if ((cword > 2)); then
case ${words[cword-2]} in case ${words[cword-2]} in

View File

@ -8,17 +8,16 @@
_service() _service()
{ {
local cur prev sysvdir local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
# don't complete past 2nd token # don't complete past 2nd token
[ $COMP_CWORD -gt 2 ] && return 0 [ $cword -gt 2 ] && return 0
if [[ $COMP_CWORD -eq 1 && $prev == "service" ]]; then if [[ $cword -eq 1 && $prev == service ]]; then
_services _services
else else
local sysvdir
[ -d /etc/rc.d/init.d ] && \ [ -d /etc/rc.d/init.d ] && \
sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \ COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \

View File

@ -4,9 +4,8 @@ have sh || return
_sh() _sh()
{ {
COMPREPLY=() local cur prev words cword
local cur prev _init_completion || return
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-c) -c)

View File

@ -3,11 +3,10 @@
have useradd && have useradd &&
_useradd() _useradd()
{ {
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
# TODO: if -o/--non-unique is given, could complete on existing uids # TODO: if -o/--non-unique is given, could complete on existing uids
@ -54,11 +53,10 @@ complete -F _useradd useradd
have usermod && have usermod &&
_usermod() _usermod()
{ {
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
# TODO: if -o/--non-unique is given, could complete on existing uids # TODO: if -o/--non-unique is given, could complete on existing uids
@ -103,10 +101,8 @@ complete -F _usermod usermod
have userdel && have userdel &&
_userdel() _userdel()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--force --help --remove' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--force --help --remove' -- "$cur" ) )
@ -120,11 +116,10 @@ complete -F _userdel userdel
have chage && have chage &&
_chage() _chage()
{ {
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
@ -149,10 +144,8 @@ complete -F _chage chage
have passwd && have passwd &&
_passwd() _passwd()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-n|-x|-w|-i|-\?|--help|--usage) -n|-x|-w|-i|-\?|--help|--usage)
@ -173,11 +166,10 @@ complete -F _passwd passwd
have chpasswd && have chpasswd &&
_chpasswd() _chpasswd()
{ {
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
@ -204,11 +196,10 @@ complete -F _chpasswd chpasswd
have newusers && have newusers &&
_newusers() _newusers()
{ {
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
@ -237,10 +228,8 @@ complete -F _newusers newusers
have pwck && have pwck &&
_pwck() _pwck()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-q -r -s' -- "$cur" ) ) COMPREPLY=( $( compgen -W '-q -r -s' -- "$cur" ) )
@ -254,11 +243,10 @@ complete -F _pwck pwck
have groupadd && have groupadd &&
_groupadd() _groupadd()
{ {
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
# TODO: if -o/--non-unique is given, could complete on existing gids # TODO: if -o/--non-unique is given, could complete on existing gids
@ -283,11 +271,10 @@ complete -F _groupadd groupadd
have groupmod && have groupmod &&
_groupmod() _groupmod()
{ {
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
# TODO: if -o/--non-unique is given, could complete on existing gids # TODO: if -o/--non-unique is given, could complete on existing gids
@ -316,9 +303,8 @@ complete -g groupdel
have newgrp && have newgrp &&
_newgrp() _newgrp()
{ {
local cur local cur prev words cword
COMPREPLY=() _init_completion || return
_get_comp_words_by_ref cur
if [[ "$cur" == "-" ]]; then if [[ "$cur" == "-" ]]; then
COMPREPLY=( - ) COMPREPLY=( - )
@ -331,10 +317,8 @@ complete -F _newgrp newgrp
have gpasswd && have gpasswd &&
_gpasswd() _gpasswd()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-a|-d|-A|-M) -a|-d|-A|-M)
@ -355,10 +339,8 @@ complete -F _gpasswd gpasswd
have groupmems && have groupmems &&
_groupmems() _groupmems()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-a|-d) -a|-d)
@ -381,10 +363,8 @@ complete -F _groupmems groupmems
have grpck && have grpck &&
_grpck() _grpck()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-r -s' -- "$cur" ) ) COMPREPLY=( $( compgen -W '-r -s' -- "$cur" ) )
@ -398,10 +378,8 @@ complete -F _grpck grpck
have vipw || have vigr && have vipw || have vigr &&
_vipw() _vipw()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-h|--help) -h|--help)
@ -420,11 +398,10 @@ complete -F _vipw vipw vigr
have faillog && have faillog &&
_faillog() _faillog()
{ {
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
@ -450,11 +427,10 @@ complete -F _faillog faillog
have lastlog && have lastlog &&
_lastlog() _lastlog()
{ {
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

@ -6,10 +6,8 @@ have sitecopy || return
_sitecopy() _sitecopy()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
case $cur in case $cur in
--*) --*)

View File

@ -105,11 +105,10 @@ _smartctl_drivedb()
_smartctl() _smartctl()
{ {
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

@ -4,10 +4,8 @@ have snownews || return
_snownews() _snownews()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
# return list of available options # return list of available options

View File

@ -4,9 +4,8 @@ have sqlite3 || return
_sqlite3() _sqlite3()
{ {
COMPREPLY=() local cur prev words cword
local cur prev _init_completion || return
_get_comp_words_by_ref cur prev
local dbexts='@(sqlite?(3)|?(s?(3))db)' local dbexts='@(sqlite?(3)|?(s?(3))db)'

View File

@ -115,13 +115,11 @@ _ssh_suboption_check()
_ssh() _ssh()
{ {
local cur prev configfile local cur prev words cword
local -a config _init_completion -n : || return
COMPREPLY=() local configfile
_get_comp_words_by_ref -n : cur prev local -a config
#cur=`_get_cword :`
#prev=`_get_pword`
_ssh_suboption_check && return 0 _ssh_suboption_check && return 0
@ -168,7 +166,7 @@ _ssh()
-i -L -l -m -O -o -p -R -S -w' -- "$cur" ) ) -i -L -l -m -O -o -p -R -S -w' -- "$cur" ) )
else else
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${COMP_WORDS[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [ "${1:0:2}" = -F ]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
@ -182,7 +180,7 @@ _ssh()
shift shift
done done
_known_hosts_real -a -F "$configfile" "$cur" _known_hosts_real -a -F "$configfile" "$cur"
if [ $COMP_CWORD -ne 1 ]; then if [ $cword -ne 1 ]; then
_compopt_o_filenames _compopt_o_filenames
COMPREPLY+=( $( compgen -c -- "$cur" ) ) COMPREPLY+=( $( compgen -c -- "$cur" ) )
fi fi
@ -196,10 +194,10 @@ shopt -u hostcomplete && complete -F _ssh ssh slogin autossh
# #
_sftp() _sftp()
{ {
local cur prev configfile local cur prev words cword
_init_completion || return
COMPREPLY=() local configfile
_get_comp_words_by_ref cur prev
_ssh_suboption_check && return 0 _ssh_suboption_check && return 0
@ -225,7 +223,7 @@ _sftp()
-- "$cur" ) ) -- "$cur" ) )
else else
# Search COMP_WORDS for '-F configfile' argument # Search COMP_WORDS for '-F configfile' argument
set -- "${COMP_WORDS[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [ "${1:0:2}" = -F ]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
@ -313,10 +311,10 @@ _scp_local_files()
# #
_scp() _scp()
{ {
local configfile cur prev prefix local cur prev words cword
_init_completion -n : || return
COMPREPLY=() local configfile prefix
_get_comp_words_by_ref -n : cur prev
_ssh_suboption_check && { _ssh_suboption_check && {
COMPREPLY=( "${COMPREPLY[@]/%/ }" ) COMPREPLY=( "${COMPREPLY[@]/%/ }" )
@ -355,7 +353,7 @@ _scp()
prefix=-F prefix=-F
else else
# Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument
set -- "${COMP_WORDS[@]}" set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "${1:0:2}" = -F ]; then if [ "${1:0:2}" = -F ]; then
if [ ${#1} -gt 2 ]; then if [ ${#1} -gt 2 ]; then
@ -395,10 +393,8 @@ complete -F _scp -o nospace scp
# #
_ssh_copy_id() _ssh_copy_id()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-i) -i)

View File

@ -4,10 +4,10 @@ have sshfs || return
_sshfs() _sshfs()
{ {
local cur userhost path local cur prev words cword
_init_completion -n : || return
COMPREPLY=() local userhost path
_get_comp_words_by_ref -n : cur
_expand || return 0 _expand || return 0

View File

@ -4,12 +4,13 @@ have strace || return
_strace() _strace()
{ {
local cur prev offset i syscalls arch unistd local cur prev words cword
_init_completion || return
# check if we're still completing strace # check if we're still completing strace
offset=0 local offset=0 i
for (( i=1; i <= COMP_CWORD; i++ )); do for (( i=1; i <= cword; i++ )); do
case ${COMP_WORDS[$i]} in case ${words[$i]} in
-o|-e|-p) -o|-e|-p)
i=$((i+1)) i=$((i+1))
continue continue
@ -26,9 +27,6 @@ _strace()
_command_offset $offset _command_offset $offset
else else
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-e) -e)
if [[ "$cur" == *=* ]]; then if [[ "$cur" == *=* ]]; then
@ -37,11 +35,12 @@ _strace()
# Import arch-specific syscalls -- not foolproof IMHO # Import arch-specific syscalls -- not foolproof IMHO
#+ --David Paleino #+ --David Paleino
arch=$(command uname -m) local arch=$(command uname -m)
syscalls=$(awk '/^#define __NR/ {print $2}' \ local syscalls=$(awk '/^#define __NR/ {print $2}' \
/usr/include/asm/unistd.h | sed -e \ /usr/include/asm/unistd.h | sed -e \
's/__NR_//') 's/__NR_//')
if [ -z "$syscalls" ]; then if [ -z "$syscalls" ]; then
local unistd
if [[ "$arch" == *86 ]]; then if [[ "$arch" == *86 ]]; then
unistd=/usr/include/asm/unistd_32.h unistd=/usr/include/asm/unistd_32.h
else else

View File

@ -4,10 +4,10 @@ have svk || return
_svk() _svk()
{ {
local cur prev commands options command local cur prev words cword
_init_completion || return
COMPREPLY=() local commands options command
_get_comp_words_by_ref cur prev
commands='add admin annotate ann blame praise cat checkout co cleanup \ commands='add admin annotate ann blame praise cat checkout co cleanup \
cmerge cm commit ci copy cp delete del remove rm depotmap \ cmerge cm commit ci copy cp delete del remove rm depotmap \
@ -17,7 +17,7 @@ _svk()
pset pull push resolved revert smerge sm status st stat switch \ pset pull push resolved revert smerge sm status st stat switch \
sw sync sy update up verify' sw sync sy update up verify'
if [[ $COMP_CWORD -eq 1 ]] ; then if [[ $cword -eq 1 ]] ; then
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--version' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--version' -- "$cur" ) )
else else
@ -36,7 +36,7 @@ _svk()
;; ;;
esac esac
command=${COMP_WORDS[1]} command=${words[1]}
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
# possible options for the command # possible options for the command

View File

@ -8,12 +8,12 @@ have sysbench || return
_sysbench() _sysbench()
{ {
COMPREPLY=() local cur prev words cword
local cur prev words split=false _init_completion -n = || return
_get_comp_words_by_ref -n = cur prev words
# long options need the "=" (whitespace split doesn't work), but we split # long options need the "=" (whitespace split doesn't work), but we split
# internally to make processing easier # internally to make processing easier
local split=false
_split_longopt && split=true _split_longopt && split=true
case $prev in case $prev in

View File

@ -4,10 +4,8 @@ have sysctl || return
_sysctl() _sysctl()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
COMPREPLY=( $( compgen -W \ COMPREPLY=( $( compgen -W \
"$( PATH="$PATH:/sbin" sysctl -N -a 2>/dev/null )" -- "$cur" ) ) "$( PATH="$PATH:/sbin" sysctl -N -a 2>/dev/null )" -- "$cur" ) )

View File

@ -5,9 +5,10 @@
have update-rc.d && have update-rc.d &&
_update_rc_d() _update_rc_d()
{ {
local cur prev sysvdir services options valid_options local cur prev words cword
_init_completion || return
_get_comp_words_by_ref cur prev local sysvdir services options valid_options
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d || sysvdir=/etc/init.d
@ -16,14 +17,14 @@ _update_rc_d()
services=( ${services[@]#$sysvdir/} ) services=( ${services[@]#$sysvdir/} )
options=( -f -n ) options=( -f -n )
if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then if [[ $cword -eq 1 || "$prev" == -* ]]; then
valid_options=( $( \ valid_options=( $( \
tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \ tr " " "\n" <<<"${words[@]} ${options[@]}" \
| sed -ne "/$( sed "s/ /\\|/g" <<<"${options[@]}" )/p" \ | sed -ne "/$( sed "s/ /\\|/g" <<<"${options[@]}" )/p" \
| sort | uniq -u \ | sort | uniq -u \
) ) ) )
COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \ COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
-X '$( tr " " "|" <<<${COMP_WORDS[@]} )' -- "$cur" ) ) -X '$( tr " " "|" <<<${words[@]} )' -- "$cur" ) )
elif [[ "$prev" == ?($( tr " " "|" <<<${services[@]} )) ]]; then elif [[ "$prev" == ?($( tr " " "|" <<<${services[@]} )) ]]; then
COMPREPLY=( $( compgen -W 'remove defaults start stop' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'remove defaults start stop' -- "$cur" ) )
elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
@ -69,9 +70,10 @@ complete -F _update_rc_d update-rc.d
have invoke-rc.d && have invoke-rc.d &&
_invoke_rc_d() _invoke_rc_d()
{ {
local cur prev sysvdir services options valid_options local cur prev words cword
_init_completion || return
_get_comp_words_by_ref cur prev local sysvdir services options valid_options
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \ [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|| sysvdir=/etc/init.d || sysvdir=/etc/init.d
@ -81,9 +83,9 @@ _invoke_rc_d()
options=( --help --quiet --force --try-anyway --disclose-deny --query \ options=( --help --quiet --force --try-anyway --disclose-deny --query \
--no-fallback ) --no-fallback )
if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then if [[ ($cword -eq 1) || ("$prev" == --* ) ]]; then
valid_options=( $( \ valid_options=( $( \
tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \ tr " " "\n" <<<"${words[@]} ${options[@]}" \
| sed -ne "/$( sed "s/ /\\\\|/g" <<<"${options[@]}" )/p" \ | sed -ne "/$( sed "s/ /\\\\|/g" <<<"${options[@]}" )/p" \
| sort | uniq -u \ | sort | uniq -u \
) ) ) )

View File

@ -4,10 +4,10 @@ have tar || return
_tar() _tar()
{ {
local cur prev words cword ext regex tar untar local cur prev words cword
_init_completion || return
COMPREPLY=() local ext regex tar untar
_get_comp_words_by_ref cur prev words cword
if [ $cword -eq 1 ]; then if [ $cword -eq 1 ]; then
COMPREPLY=( $( compgen -W 'c t x u r d A' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'c t x u r d A' -- "$cur" ) )
@ -65,7 +65,7 @@ _tar()
# complete on files in tar file # complete on files in tar file
# #
# get name of tar file from command line # get name of tar file from command line
tar=$( sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' <<<"$COMP_LINE" ) tar=$( sed -e 's/^.* \([^ ]*'$regex'\) .*$/\1/' <<<"${words[@]}" )
# devise how to untar and list it # devise how to untar and list it
untar=t${words[1]//[^IJzjyf]/} untar=t${words[1]//[^IJzjyf]/}

View File

@ -4,10 +4,8 @@ have tcpdump || return
_tcpdump() _tcpdump()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-r|-w|-F) -r|-w|-F)

View File

@ -4,15 +4,13 @@ have unace || return
_unace() _unace()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]] ; then if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W '-c -c- -f -f- -o -o- -p -y -y-' -- "$cur" ) ) COMPREPLY=( $( compgen -W '-c -c- -f -f- -o -o- -p -y -y-' -- "$cur" ) )
else else
if [ $COMP_CWORD -eq 1 ]; then if [ $cword -eq 1 ]; then
COMPREPLY=( $( compgen -W 'e l t v x' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'e l t v x' -- "$cur" ) )
else else
_filedir ace _filedir ace

View File

@ -4,17 +4,15 @@ have unrar || return
_unrar() _unrar()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]] ; then if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W '-ad -ap -av- -c- -cfg- -cl -cu \ COMPREPLY=( $( compgen -W '-ad -ap -av- -c- -cfg- -cl -cu \
-dh -ep -f -idp -ierr -inul -kb -o+ -o- -ow -p -p- -r -ta \ -dh -ep -f -idp -ierr -inul -kb -o+ -o- -ow -p -p- -r -ta \
-tb -tn -to -u -v -ver -vp -x -x@ -y' -- "$cur" ) ) -tb -tn -to -u -v -ver -vp -x -x@ -y' -- "$cur" ) )
else else
if [ $COMP_CWORD -eq 1 ]; then if [ $cword -eq 1 ]; then
COMPREPLY=( $( compgen -W 'e l lb lt p t v vb vt x' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'e l lb lt p t v vb vt x' -- "$cur" ) )
else else
_filedir rar _filedir rar

View File

@ -9,9 +9,9 @@ _installed_alternatives()
for i in alternatives dpkg/alternatives rpm/alternatives; do for i in alternatives dpkg/alternatives rpm/alternatives; do
[ -d /var/lib/$i ] && admindir=/var/lib/$i && break [ -d /var/lib/$i ] && admindir=/var/lib/$i && break
done done
for (( i=1; i < COMP_CWORD; i++ )); do for (( i=1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == --admindir ]]; then if [[ "${words[i]}" == --admindir ]]; then
admindir=${COMP_WORDS[i+1]} admindir=${words[i+1]}
break break
fi fi
done done
@ -20,10 +20,8 @@ _installed_alternatives()
_update_alternatives() _update_alternatives()
{ {
local cur prev mode args i local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
--altdir|--admindir) --altdir|--admindir)
@ -35,11 +33,13 @@ _update_alternatives()
;; ;;
esac esac
local mode args i
# find which mode to use and how many real args used so far # find which mode to use and how many real args used so far
for (( i=1; i < COMP_CWORD; i++ )); do for (( i=1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then if [[ "${words[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then
mode=${COMP_WORDS[i]} mode=${words[i]}
args=$(($COMP_CWORD - i)) args=$(($cword - i))
break break
fi fi
done done

View File

@ -5,16 +5,14 @@
have renice && have renice &&
_renice() _renice()
{ {
local command cur curopt i local cur prev words cword
_init_completion || return
COMPREPLY=() local command=$1 curopt i=0
_get_comp_words_by_ref cur
command=$1
i=0
# walk back through command line and find last option # walk back through command line and find last option
while [[ $i -le $COMP_CWORD && ${#COMPREPLY[@]} -eq 0 ]]; do while [[ $i -le $cword && ${#COMPREPLY[@]} -eq 0 ]]; do
curopt=${COMP_WORDS[COMP_CWORD-$i]} curopt=${words[cword-$i]}
case "$curopt" in case "$curopt" in
-u) -u)
_allowed_users _allowed_users
@ -36,12 +34,10 @@ complete -F _renice renice
have kill && have kill &&
_kill() _kill()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=() if [[ $cword -eq 1 && "$cur" == -* ]]; then
_get_comp_words_by_ref cur
if [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then
# return list of available signals # return list of available signals
_signals _signals
else else
@ -56,12 +52,10 @@ complete -F _kill kill
have look && have look &&
_look() _look()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=() if [[ $cword -eq 1 ]]; then
_get_comp_words_by_ref cur
if [[ $COMP_CWORD -eq 1 ]]; then
COMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur" ) ) COMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur" ) )
fi fi
} && } &&

View File

@ -20,10 +20,8 @@ complete -F _vncviewer_bootstrap vncviewer
have tightvncviewer && have tightvncviewer &&
_tightvncviewer() _tightvncviewer()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-passwd) -passwd)
@ -61,10 +59,8 @@ complete -F _tightvncviewer tightvncviewer
have xvnc4viewer && have xvnc4viewer &&
_xvnc4viewer() _xvnc4viewer()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
# Convert double dash to single dash # Convert double dash to single dash
case ${prev/#--/-} in case ${prev/#--/-} in

View File

@ -4,10 +4,8 @@ have vpnc || return
_vpnc() _vpnc()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
--pfs) --pfs)

View File

@ -5,10 +5,8 @@
have iwconfig && have iwconfig &&
_iwconfig() _iwconfig()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
mode) mode)
@ -20,7 +18,7 @@ _iwconfig()
COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
if [ -n "${COMP_IWLIST_SCAN:-}" ]; then if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
COMPREPLY+=( $( compgen -W \ COMPREPLY+=( $( compgen -W \
"$( iwlist ${COMP_WORDS[1]} scan | \ "$( iwlist ${words[1]} scan | \
awk -F'\"' '/ESSID/ {print $2}' )" -- "$cur" ) ) awk -F'\"' '/ESSID/ {print $2}' )" -- "$cur" ) )
fi fi
return 0 return 0
@ -30,13 +28,13 @@ _iwconfig()
return 0 return 0
;; ;;
channel) channel)
COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \ COMPREPLY=( $( compgen -W "$( iwlist ${words[1]} channel | \
awk '/^[ \t]*Channel/ {print $2}' )" -- "$cur" ) ) awk '/^[ \t]*Channel/ {print $2}' )" -- "$cur" ) )
return 0 return 0
;; ;;
freq) freq)
COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \ COMPREPLY=( $( compgen -W "$( iwlist ${words[1]} channel | \
awk '/^[ \t]*Channel/ {print $4"G"}')" -- "$cur" ) ) awk '/^[ \t]*Channel/ {print $4"G"}')" -- "$cur" ) )
return 0 return 0
;; ;;
@ -44,7 +42,7 @@ _iwconfig()
COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) )
if [ -n "${COMP_IWLIST_SCAN:-}" ]; then if [ -n "${COMP_IWLIST_SCAN:-}" ]; then
COMPREPLY+=( $( compgen -W \ COMPREPLY+=( $( compgen -W \
"$( iwlist ${COMP_WORDS[1]} scan | \ "$( iwlist ${words[1]} scan | \
awk -F ': ' '/Address/ {print $2}' )" -- "$cur" ) ) awk -F ': ' '/Address/ {print $2}' )" -- "$cur" ) )
fi fi
return 0 return 0
@ -52,7 +50,7 @@ _iwconfig()
rate) rate)
COMPREPLY=( $( compgen -W 'auto fixed' -- "$cur" ) ) COMPREPLY=( $( compgen -W 'auto fixed' -- "$cur" ) )
COMPREPLY+=( $( compgen -W \ COMPREPLY+=( $( compgen -W \
"$( iwlist ${COMP_WORDS[1]} rate | \ "$( iwlist ${words[1]} rate | \
awk '/^[ \t]*[0-9]/ {print $1"M"}' )" -- "$cur" ) ) awk '/^[ \t]*[0-9]/ {print $1"M"}' )" -- "$cur" ) )
return 0 return 0
;; ;;
@ -78,7 +76,7 @@ _iwconfig()
;; ;;
esac esac
if [ $COMP_CWORD -eq 1 ]; then if [ $cword -eq 1 ]; then
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else else
@ -96,12 +94,10 @@ complete -F _iwconfig iwconfig
have iwlist && have iwlist &&
_iwlist() _iwlist()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=() if [ $cword -eq 1 ]; then
_get_comp_words_by_ref cur prev
if [ $COMP_CWORD -eq 1 ]; then
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else else
@ -119,12 +115,10 @@ complete -F _iwlist iwlist
have iwspy && have iwspy &&
_iwspy() _iwspy()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=() if [ $cword -eq 1 ]; then
_get_comp_words_by_ref cur
if [ $COMP_CWORD -eq 1 ]; then
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else else
@ -140,10 +134,8 @@ complete -F _iwspy iwspy
have iwpriv && have iwpriv &&
_iwpriv() _iwpriv()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
roam) roam)
@ -156,7 +148,7 @@ _iwpriv()
;; ;;
esac esac
if [ $COMP_CWORD -eq 1 ]; then if [ $cword -eq 1 ]; then
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) )
else else

View File

@ -8,10 +8,10 @@ have cdrecord || have wodim || return
_cdrecord() _cdrecord()
{ {
local cur prev i generic_options track_options track_mode local cur prev words cword
_init_completion -n = || return
COMPREPLY=() local i generic_options track_options track_mode
_get_comp_words_by_ref -n = cur prev
# foo=bar style option # foo=bar style option
if [[ "$cur" == *=* ]]; then if [[ "$cur" == *=* ]]; then
@ -82,7 +82,7 @@ _cdrecord()
-copy -nocopy -scms isrc= index= padsize= pregap= tsize= ) -copy -nocopy -scms isrc= index= padsize= pregap= tsize= )
# look if previous was either a file or a track option # look if previous was either a file or a track option
track_mode=0 track_mode=0
if [ $COMP_CWORD -gt 1 ]; then if [ $cword -gt 1 ]; then
if [ -f "$prev" ]; then if [ -f "$prev" ]; then
track_mode=1 track_mode=1
else else

View File

@ -4,9 +4,10 @@ have wol || return
_wol() _wol()
{ {
local cur prev split=false local cur prev words cword
COMPREPLY=() _init_completion -n : || return
_get_comp_words_by_ref -n : cur prev
local split=false
_split_longopt && split=true _split_longopt && split=true
case $prev in case $prev in

View File

@ -5,15 +5,15 @@ have wtf || return
_wtf() _wtf()
{ {
local cur prev db local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
[ "$prev" = -f ] && _filedir && return 0 [ "$prev" = -f ] && _filedir && return 0
[[ "$cur" == -* ]] && COMPREPLY=( -f ) && return 0 [[ "$cur" == -* ]] && COMPREPLY=( -f ) && return 0
set -- "${COMP_WORDS[@]}" local db
set -- "${words[@]}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
if [ "$1" = -f ]; then if [ "$1" = -f ]; then
shift ; db=$1 ; break shift ; db=$1 ; break

View File

@ -4,10 +4,8 @@ have wvdial || return
_wvdial() _wvdial()
{ {
local cur prev config i IFS=$'\n' local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
--config) --config)
@ -16,6 +14,8 @@ _wvdial()
;; ;;
esac esac
local config i IFS=$'\n'
case $cur in case $cur in
-*) -*)
COMPREPLY=( $( compgen -W '--config --chat \ COMPREPLY=( $( compgen -W '--config --chat \
@ -26,9 +26,9 @@ _wvdial()
# start with global and personal config files # start with global and personal config files
config="/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc" config="/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc"
# replace with command line config file if present # replace with command line config file if present
for (( i=1; i < COMP_CWORD; i++ )); do for (( i=1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == "--config" ]]; then if [[ "${words[i]}" == "--config" ]]; then
config=${COMP_WORDS[i+1]} config=${words[i+1]}
break break
fi fi
done done

View File

@ -4,8 +4,8 @@ have xhost || return
_xhost () _xhost ()
{ {
local cur local cur prev words cword
_get_comp_words_by_ref cur _init_completion || return
case $cur in case $cur in
+*) _known_hosts_real -p+ "${cur:1}" ;; +*) _known_hosts_real -p+ "${cur:1}" ;;

View File

@ -16,12 +16,12 @@ _xen_domain_ids()
_xm() _xm()
{ {
local cur prev words cword
_init_completion || return
# TODO: _split_longopt # TODO: _split_longopt
local cur prev command options local command options
COMPREPLY=()
_get_comp_words_by_ref cur prev
commands='console vncviewer create new delete destroy domid domname \ commands='console vncviewer create new delete destroy domid domname \
dump-core list mem-max mem-set migrate pause reboot rename reset \ dump-core list mem-max mem-set migrate pause reboot rename reset \
@ -34,7 +34,7 @@ _xm()
labels addlabel rmlabel getlabel dry-run resources dumppolicy \ labels addlabel rmlabel getlabel dry-run resources dumppolicy \
setpolicy resetpolicy getpolicy shell help' setpolicy resetpolicy getpolicy shell help'
if [[ $COMP_CWORD -eq 1 ]] ; then if [[ $cword -eq 1 ]] ; then
COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) )
else else
if [[ "$cur" == *=* ]]; then if [[ "$cur" == *=* ]]; then
@ -42,7 +42,7 @@ _xm()
cur=${cur/*=/} cur=${cur/*=/}
fi fi
command=${COMP_WORDS[1]} command=${words[1]}
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
# possible options for the command # possible options for the command
case $command in case $command in

View File

@ -4,10 +4,8 @@ have xmllint || return
_xmllint() _xmllint()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-o|--output) -o|--output)

View File

@ -4,10 +4,8 @@ have xmlwf || return
_xmlwf() _xmlwf()
{ {
local cur prev local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-d) -d)

View File

@ -4,10 +4,8 @@ have xmms || return
_xmms() _xmms()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \ COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \

View File

@ -4,9 +4,8 @@ have xmodmap || return
_xmodmap() _xmodmap()
{ {
COMPREPLY=() local cur prev words cword
local cur prev _init_completion || return
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-display|-e) -display|-e)

View File

@ -4,9 +4,10 @@ have xrandr || return
_xrandr() _xrandr()
{ {
local cur prev output modes local cur prev words cword
COMPREPLY=() _init_completion || return
_get_comp_words_by_ref cur prev
local output modes
case $prev in case $prev in
--output) --output)
@ -15,9 +16,9 @@ _xrandr()
return 0 return 0
;; ;;
--mode) --mode)
for(( i = 1; i < COMP_CWORD; i++ )); do for(( i = 1; i < cword; i++ )); do
if [[ "${COMP_WORDS[i]}" == "--output" ]]; then if [[ "${words[i]}" == "--output" ]]; then
output=${COMP_WORDS[i+1]} output=${words[i+1]}
break break
fi fi
done done

View File

@ -4,9 +4,8 @@ have xrdb || return
_xrdb() _xrdb()
{ {
COMPREPLY=() local cur prev words cword
local cur prev _init_completion || return
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-backup|-display|-help) -backup|-display|-help)

View File

@ -4,9 +4,8 @@ have xsltproc || return
_xsltproc() _xsltproc()
{ {
local cur prev local cur prev words cword
COMPREPLY=() _init_completion || return
_get_comp_words_by_ref cur prev
case $prev in case $prev in
--output|-o) --output|-o)
@ -37,7 +36,7 @@ _xsltproc()
;; ;;
esac esac
[[ $COMP_CWORD -gt 2 && `_get_cword '' 2` == --?(string)param ]] && \ [[ $cword -gt 2 && `_get_cword '' 2` == --?(string)param ]] && \
return 0 return 0
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then

View File

@ -3,9 +3,8 @@
have xz || have pxz && have xz || have pxz &&
_xz() _xz()
{ {
COMPREPLY=() local cur prev words cword
local cur prev _init_completion || return
_get_comp_words_by_ref cur prev
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--compress --decompress --test --list \ COMPREPLY=( $( compgen -W '--compress --decompress --test --list \
@ -64,9 +63,8 @@ complete -F _xz xz pxz
have xzdec && have xzdec &&
_xzdec() _xzdec()
{ {
COMPREPLY=() local cur prev words cword
local cur prev _init_completion || return
_get_comp_words_by_ref cur prev
if [[ "$cur" == -* ]]; then if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--memory --quiet --help --version' \ COMPREPLY=( $( compgen -W '--memory --quiet --help --version' \

View File

@ -4,22 +4,20 @@ have ypcat || return
_ypmatch() _ypmatch()
{ {
local cur map cmd local cur prev words cword
_init_completion || return
COMPREPLY=() local map cmd=${1##*/}
_get_comp_words_by_ref cur
cmd=${1##*/}
[[ $cmd == ypcat && $COMP_CWORD -gt 1 ]] && return 0 [[ $cmd == ypcat && $cword -gt 1 ]] && return 0
[[ $cmd == ypmatch && $COMP_CWORD -gt 2 ]] && return 0 [[ $cmd == ypmatch && $cword -gt 2 ]] && return 0
if [[ $cmd == ypmatch && $COMP_CWORD -eq 1 && \ if [[ $cmd == ypmatch && $cword -eq 1 && ${#words[@]} -eq 3 ]]; then
${#COMP_WORDS[@]} -eq 3 ]]; then map=${words[2]}
map=${COMP_WORDS[2]}
COMPREPLY=( $( compgen -W '$( ypcat $map | \ COMPREPLY=( $( compgen -W '$( ypcat $map | \
cut -d':' -f 1 )' -- "$cur") ) cut -d':' -f 1 )' -- "$cur") )
else else
[[ $cmd == ypmatch && $COMP_CWORD -ne 2 ]] && return 0 [[ $cmd == ypmatch && $cword -ne 2 ]] && return 0
COMPREPLY=( $( compgen -W \ COMPREPLY=( $( compgen -W \
'$( printf "%s\n" $(ypcat -x | cut -d"\"" -f 2) )' -- "$cur")) '$( printf "%s\n" $(ypcat -x | cut -d"\"" -f 2) )' -- "$cur"))
fi fi

View File

@ -4,9 +4,8 @@ have yum-arch || return
_yum_arch() _yum_arch()
{ {
local cur local cur prev words cword
COMPREPLY=() _init_completion || return
_get_comp_words_by_ref cur
if [[ "$cur" == -* ]] ; then if [[ "$cur" == -* ]] ; then
COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- "$cur" ) ) COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- "$cur" ) )