diff options
author | Ville Skyttä <ville.skytta@iki.fi> | 2011-04-21 11:04:51 +0300 |
---|---|---|
committer | Ville Skyttä <ville.skytta@iki.fi> | 2011-04-21 11:15:01 +0300 |
commit | 8048917968a679f3eecfd5fd237a7ee2823ab855 (patch) | |
tree | f8f9e67299a0005b1b2441c3232f4c08932385e9 | |
parent | e3ca91b9866e60ac541c9a1cf065b855a1681bc3 (diff) | |
download | bash-completion-8048917968a679f3eecfd5fd237a7ee2823ab855.tar.gz |
Use _init_completion() in completions/[q-z]*.
58 files changed, 337 insertions, 458 deletions
diff --git a/completions/qdbus b/completions/qdbus index 2b7f2e72..ffdea33b 100644 --- a/completions/qdbus +++ b/completions/qdbus @@ -4,13 +4,11 @@ have qdbus || have dcop || return _qdbus() { - local cur + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur - - [ -n "$cur" ] && unset COMP_WORDS[${#COMP_WORDS[@]}-1] - COMPREPLY=( $( compgen -W '$( command ${COMP_WORDS[@]} 2>/dev/null | \ + [ -n "$cur" ] && unset words[${#words[@]}-1] + COMPREPLY=( $( compgen -W '$( command ${words[@]} 2>/dev/null | \ sed s/\(.*\)// )' -- "$cur" ) ) } && complete -F _qdbus qdbus dcop diff --git a/completions/qemu b/completions/qemu index 5cac45e2..f0933996 100644 --- a/completions/qemu +++ b/completions/qemu @@ -4,10 +4,8 @@ have qemu || return _qemu() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -fd[ab]|-hd[abcd]|-cdrom|-option-rom|-kernel|-initrd|-bootp|-pidfile| \ diff --git a/completions/quota-tools b/completions/quota-tools index e2931412..bc06607a 100644 --- a/completions/quota-tools +++ b/completions/quota-tools @@ -7,8 +7,8 @@ _user_or_group() local i # complete on groups if -g was given - for (( i=1; i < COMP_CWORD; i++ )); do - if [[ "${COMP_WORDS[i]}" == -g ]]; then + for (( i=1; i < cword; i++ )); do + if [[ "${words[i]}" == -g ]]; then COMPREPLY=( $( compgen -g -- "$cur" ) ) return 0 fi @@ -33,11 +33,10 @@ _filesystems() _quota() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -62,11 +61,10 @@ complete -F _quota -o default quota _setquota() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -101,11 +99,10 @@ complete -F _setquota -o default setquota _edquota() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -133,11 +130,10 @@ complete -F _edquota -o default edquota _quotacheck() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -162,11 +158,10 @@ complete -F _quotacheck -o default quotacheck _repquota() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -191,11 +186,10 @@ complete -F _repquota -o default repquota _quotaon() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -218,11 +212,10 @@ complete -F _quotaon -o default quotaon _quotaoff() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in diff --git a/completions/rcs b/completions/rcs index 30b08f9d..9b150109 100644 --- a/completions/rcs +++ b/completions/rcs @@ -4,10 +4,10 @@ have rcs || return _rcs() { - local cur prev file dir i + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur prev + local file dir i file=${cur##*/} dir=${cur%/*} diff --git a/completions/rdesktop b/completions/rdesktop index 267f75f8..cb83a5dc 100644 --- a/completions/rdesktop +++ b/completions/rdesktop @@ -4,10 +4,8 @@ have rdesktop || return _rdesktop() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -k) diff --git a/completions/reportbug b/completions/reportbug index 0c44bd68..223bcf33 100644 --- a/completions/reportbug +++ b/completions/reportbug @@ -3,10 +3,8 @@ have reportbug && _reportbug() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -f|--filename|-i|--include|--mta|-o|--output) @@ -19,8 +17,8 @@ _reportbug() return 0 ;; -e|--editor|--mua) - COMP_WORDS=(COMP_WORDS[0] "$cur") - COMP_CWORD=1 + words=(words[0] "$cur") + cword=1 _command return 0 ;; @@ -89,11 +87,10 @@ complete -F _reportbug reportbug have querybts && _querybts() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in diff --git a/completions/reptyr b/completions/reptyr index d1ccdb3c..4d1a9c46 100644 --- a/completions/reptyr +++ b/completions/reptyr @@ -4,10 +4,8 @@ have reptyr || return _reptyr() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -l) diff --git a/completions/resolvconf b/completions/resolvconf index f21adc3e..83cbdb07 100644 --- a/completions/resolvconf +++ b/completions/resolvconf @@ -4,10 +4,8 @@ have resolvconf || return _resolvconf() { - local cur command - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -a|-d) diff --git a/completions/rfkill b/completions/rfkill index 50e79ab4..f0d4f1cc 100644 --- a/completions/rfkill +++ b/completions/rfkill @@ -4,15 +4,13 @@ have rfkill || return _rfkill() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--version' -- "$cur" ) ) else - case $COMP_CWORD in + case $cword in 1) COMPREPLY=( $( compgen -W "help event list block unblock" \ -- "$cur" ) ) diff --git a/completions/ri b/completions/ri index f2c152a7..f0658d7f 100644 --- a/completions/ri +++ b/completions/ri @@ -35,11 +35,11 @@ ri_get_methods() # needs at least Ruby 1.8.0 in order to use -W0 _ri() { - local cur class method prefix ri_path ri_version separator IFS - local -a classes + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur + local class method prefix ri_path ri_version separator IFS + local -a classes ri_path=$(type -p ri) # which version of ri are we using? diff --git a/completions/rpcdebug b/completions/rpcdebug index f1590a67..facc8517 100644 --- a/completions/rpcdebug +++ b/completions/rpcdebug @@ -7,9 +7,9 @@ _rpcdebug_flags() local i module - for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do - if [[ ${COMP_WORDS[i]} == -m ]]; then - module=${COMP_WORDS[i+1]} + for (( i=0; i < ${#words[@]}; i++ )); do + if [[ ${words[i]} == -m ]]; then + module=${words[i+1]} fi done @@ -21,10 +21,8 @@ _rpcdebug_flags() _rpcdebug() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -s) diff --git a/completions/rpm b/completions/rpm index 94ce6569..005cfbda 100644 --- a/completions/rpm +++ b/completions/rpm @@ -39,12 +39,10 @@ _rpm_macros() # _rpm() { - local cur prev opts + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur prev - - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then # first parameter on line case $cur in --*) @@ -117,10 +115,10 @@ _rpm() esac # options common to all modes - opts="--define --eval --macros --nodigest --nosignature --rcfile \ + local opts="--define --eval --macros --nodigest --nosignature --rcfile \ --quiet --pipe --verbose" - case ${COMP_WORDS[1]} in + case ${words[1]} in -[iFU]*|--install|--freshen|--upgrade) if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W "$opts --percent --force \ @@ -152,7 +150,7 @@ _rpm() --list --obsoletes --pipe --provides --queryformat --rcfile --requires --scripts --suggests --triggers --xml" - if [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then + if [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then # -qf completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W "$opts --dbpath --fscontext \ @@ -160,10 +158,10 @@ _rpm() else _filedir fi - elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then + elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then # -qg completion _rpm_groups $1 - elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then + elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then # -qp; uninstalled package completion if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W "$opts --ftpport --ftpproxy \ @@ -179,7 +177,7 @@ _rpm() --package --pkgid --root --specfile --state --triggeredby --whatprovides --whatrequires" \ -- "$cur" ) ) - elif [[ $COMP_LINE != *\ -@(*([^ -])a|-all )* ]]; then + elif [[ ${words[@]} != *\ -@(*([^ -])a|-all )* ]]; then _rpm_installed_packages $1 fi fi @@ -199,11 +197,11 @@ _rpm() --nofiles --noscripts --nomd5 --querytags --specfile \ --whatrequires --whatprovides" -- "$cur" ) ) # check whether we're doing file completion - elif [[ $COMP_LINE == *\ -@(*([^ -])f|-file )* ]]; then + elif [[ ${words[@]} == *\ -@(*([^ -])f|-file )* ]]; then _filedir - elif [[ $COMP_LINE == *\ -@(*([^ -])g|-group )* ]]; then + elif [[ ${words[@]} == *\ -@(*([^ -])g|-group )* ]]; then _rpm_groups $1 - elif [[ $COMP_LINE == *\ -@(*([^ -])p|-package )* ]]; then + elif [[ ${words[@]} == *\ -@(*([^ -])p|-package )* ]]; then _filedir '[rs]pm' else _rpm_installed_packages $1 @@ -231,10 +229,10 @@ complete -F _rpm rpm _rpmbuild() { - COMPREPLY=() - local cur prev words split=false - _get_comp_words_by_ref cur prev words + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true local rpm="${1%build*}" @@ -304,14 +302,10 @@ complete -F _rpmbuild rpmbuild rpmbuild-md5 have gendiff && _gendiff() { - COMPREPLY=() - local cur prev cword - _get_comp_words_by_ref cur prev cword - if [[ $cword -eq 1 ]]; then - _filedir -d - elif [[ $prev == *\> ]]; then - _filedir - fi + local cur prev words cword + _init_completion -o @(diff|patch) || return + + [[ $cword -eq 1 ]] && _filedir -d } && complete -F _gendiff gendiff diff --git a/completions/rpmcheck b/completions/rpmcheck index 9dd33119..16d96da6 100644 --- a/completions/rpmcheck +++ b/completions/rpmcheck @@ -4,10 +4,8 @@ have rpmcheck || return _rpmcheck() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -base) diff --git a/completions/rrdtool b/completions/rrdtool index b2ad71f5..817b1aea 100644 --- a/completions/rrdtool +++ b/completions/rrdtool @@ -4,8 +4,8 @@ have rrdtool || return _rrdtool () { - local cur - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return COMPREPLY=( $( compgen -W 'create update updatev graph dump restore last \ lastupdate first info fetch tune resize xport' -- "$cur" ) ) diff --git a/completions/rsync b/completions/rsync index 12992025..5c07db40 100644 --- a/completions/rsync +++ b/completions/rsync @@ -4,11 +4,10 @@ have rsync || return _rsync() { - # TODO: _split_longopt + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - local cur prev - _get_comp_words_by_ref -n : cur prev + # TODO: _split_longopt _expand || return 0 @@ -65,9 +64,9 @@ _rsync() if type _scp_remote_files &>/dev/null; then # find which remote shell is used local i shell=ssh - for (( i=1; i < COMP_CWORD; i++ )); do - if [[ "${COMP_WORDS[i]}" == -@(e|-rsh) ]]; then - shell=${COMP_WORDS[i+1]} + for (( i=1; i < cword; i++ )); do + if [[ "${words[i]}" == -@(e|-rsh) ]]; then + shell=${words[i+1]} break fi done diff --git a/completions/rtcwake b/completions/rtcwake index 9f2e896e..7cfb49bd 100644 --- a/completions/rtcwake +++ b/completions/rtcwake @@ -4,10 +4,10 @@ have rtcwake || return _rtcwake() { - COMPREPLY=() - local cur prev split=false - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case "$prev" in diff --git a/completions/samba b/completions/samba index 7568a561..a08b9ee3 100644 --- a/completions/samba +++ b/completions/samba @@ -30,11 +30,10 @@ _samba_debuglevel() _smbclient() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -96,11 +95,10 @@ complete -F _smbclient smbclient _smbget() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -128,11 +126,10 @@ complete -F _smbget smbget _smbcacls() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -161,11 +158,10 @@ complete -F _smbcacls smbcacls _smbcquotas() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -195,10 +191,8 @@ complete -F _smbcquotas smbcquotas _smbpasswd() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -r) @@ -228,10 +222,8 @@ complete -F _smbpasswd smbpasswd _smbtar() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -r|-t) @@ -257,11 +249,10 @@ complete -F _smbtar smbtar _smbtree() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in diff --git a/completions/sbcl b/completions/sbcl index 7bf1ab97..85d0b437 100644 --- a/completions/sbcl +++ b/completions/sbcl @@ -5,10 +5,8 @@ have sbcl || have sbcl-mt || return _sbcl() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return # completing an option (may or may not be separated by a space) if [[ "$cur" == -* ]]; then diff --git a/completions/screen b/completions/screen index 15aaa780..e2d99bd4 100644 --- a/completions/screen +++ b/completions/screen @@ -11,9 +11,7 @@ _screen_sessions() _screen() { local cur prev words cword - - COMPREPLY=() - _get_comp_words_by_ref cur prev words cword + _init_completion || return if ((cword > 2)); then case ${words[cword-2]} in diff --git a/completions/service b/completions/service index f45c5300..515c6d15 100644 --- a/completions/service +++ b/completions/service @@ -8,17 +8,16 @@ _service() { - local cur prev sysvdir - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return # 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 else + local sysvdir [ -d /etc/rc.d/init.d ] && \ sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \ diff --git a/completions/sh b/completions/sh index 79a546ad..2ca56e8e 100644 --- a/completions/sh +++ b/completions/sh @@ -4,9 +4,8 @@ have sh || return _sh() { - COMPREPLY=() - local cur prev - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -c) diff --git a/completions/shadow b/completions/shadow index 058c1397..82bdf52a 100644 --- a/completions/shadow +++ b/completions/shadow @@ -3,11 +3,10 @@ have useradd && _useradd() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true # TODO: if -o/--non-unique is given, could complete on existing uids @@ -54,11 +53,10 @@ complete -F _useradd useradd have usermod && _usermod() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true # TODO: if -o/--non-unique is given, could complete on existing uids @@ -103,10 +101,8 @@ complete -F _usermod usermod have userdel && _userdel() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--force --help --remove' -- "$cur" ) ) @@ -120,11 +116,10 @@ complete -F _userdel userdel have chage && _chage() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -149,10 +144,8 @@ complete -F _chage chage have passwd && _passwd() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -n|-x|-w|-i|-\?|--help|--usage) @@ -173,11 +166,10 @@ complete -F _passwd passwd have chpasswd && _chpasswd() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -204,11 +196,10 @@ complete -F _chpasswd chpasswd have newusers && _newusers() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -237,10 +228,8 @@ complete -F _newusers newusers have pwck && _pwck() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-q -r -s' -- "$cur" ) ) @@ -254,11 +243,10 @@ complete -F _pwck pwck have groupadd && _groupadd() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true # TODO: if -o/--non-unique is given, could complete on existing gids @@ -283,11 +271,10 @@ complete -F _groupadd groupadd have groupmod && _groupmod() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true # TODO: if -o/--non-unique is given, could complete on existing gids @@ -316,9 +303,8 @@ complete -g groupdel have newgrp && _newgrp() { - local cur - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == "-" ]]; then COMPREPLY=( - ) @@ -331,10 +317,8 @@ complete -F _newgrp newgrp have gpasswd && _gpasswd() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -a|-d|-A|-M) @@ -355,10 +339,8 @@ complete -F _gpasswd gpasswd have groupmems && _groupmems() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -a|-d) @@ -381,10 +363,8 @@ complete -F _groupmems groupmems have grpck && _grpck() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-r -s' -- "$cur" ) ) @@ -398,10 +378,8 @@ complete -F _grpck grpck have vipw || have vigr && _vipw() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -h|--help) @@ -420,11 +398,10 @@ complete -F _vipw vipw vigr have faillog && _faillog() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in @@ -450,11 +427,10 @@ complete -F _faillog faillog have lastlog && _lastlog() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in diff --git a/completions/sitecopy b/completions/sitecopy index 2535e85b..d0dc9024 100644 --- a/completions/sitecopy +++ b/completions/sitecopy @@ -6,10 +6,8 @@ have sitecopy || return _sitecopy() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return case $cur in --*) diff --git a/completions/smartctl b/completions/smartctl index 1930848c..e7e71836 100644 --- a/completions/smartctl +++ b/completions/smartctl @@ -105,11 +105,10 @@ _smartctl_drivedb() _smartctl() { - local cur prev split=false - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + local split=false _split_longopt && split=true case $prev in diff --git a/completions/snownews b/completions/snownews index c579bca6..ee7ec981 100644 --- a/completions/snownews +++ b/completions/snownews @@ -4,10 +4,8 @@ have snownews || return _snownews() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then # return list of available options diff --git a/completions/sqlite3 b/completions/sqlite3 index 75618d20..fe76652a 100644 --- a/completions/sqlite3 +++ b/completions/sqlite3 @@ -4,9 +4,8 @@ have sqlite3 || return _sqlite3() { - COMPREPLY=() - local cur prev - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return local dbexts='@(sqlite?(3)|?(s?(3))db)' diff --git a/completions/ssh b/completions/ssh index 3276cd01..5237dda1 100644 --- a/completions/ssh +++ b/completions/ssh @@ -115,13 +115,11 @@ _ssh_suboption_check() _ssh() { - local cur prev configfile - local -a config + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev - #cur=`_get_cword :` - #prev=`_get_pword` + local configfile + local -a config _ssh_suboption_check && return 0 @@ -168,7 +166,7 @@ _ssh() -i -L -l -m -O -o -p -R -S -w' -- "$cur" ) ) else # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument - set -- "${COMP_WORDS[@]}" + set -- "${words[@]}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -182,7 +180,7 @@ _ssh() shift done _known_hosts_real -a -F "$configfile" "$cur" - if [ $COMP_CWORD -ne 1 ]; then + if [ $cword -ne 1 ]; then _compopt_o_filenames COMPREPLY+=( $( compgen -c -- "$cur" ) ) fi @@ -196,10 +194,10 @@ shopt -u hostcomplete && complete -F _ssh ssh slogin autossh # _sftp() { - local cur prev configfile + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur prev + local configfile _ssh_suboption_check && return 0 @@ -225,7 +223,7 @@ _sftp() -- "$cur" ) ) else # Search COMP_WORDS for '-F configfile' argument - set -- "${COMP_WORDS[@]}" + set -- "${words[@]}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -313,10 +311,10 @@ _scp_local_files() # _scp() { - local configfile cur prev prefix + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev + local configfile prefix _ssh_suboption_check && { COMPREPLY=( "${COMPREPLY[@]/%/ }" ) @@ -355,7 +353,7 @@ _scp() prefix=-F else # Search COMP_WORDS for '-F configfile' or '-Fconfigfile' argument - set -- "${COMP_WORDS[@]}" + set -- "${words[@]}" while [ $# -gt 0 ]; do if [ "${1:0:2}" = -F ]; then if [ ${#1} -gt 2 ]; then @@ -395,10 +393,8 @@ complete -F _scp -o nospace scp # _ssh_copy_id() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -i) diff --git a/completions/sshfs b/completions/sshfs index c4d2edd6..ce34d951 100644 --- a/completions/sshfs +++ b/completions/sshfs @@ -4,10 +4,10 @@ have sshfs || return _sshfs() { - local cur userhost path + local cur prev words cword + _init_completion -n : || return - COMPREPLY=() - _get_comp_words_by_ref -n : cur + local userhost path _expand || return 0 diff --git a/completions/strace b/completions/strace index 06374536..e7296ca7 100644 --- a/completions/strace +++ b/completions/strace @@ -4,12 +4,13 @@ have strace || return _strace() { - local cur prev offset i syscalls arch unistd + local cur prev words cword + _init_completion || return # check if we're still completing strace - offset=0 - for (( i=1; i <= COMP_CWORD; i++ )); do - case ${COMP_WORDS[$i]} in + local offset=0 i + for (( i=1; i <= cword; i++ )); do + case ${words[$i]} in -o|-e|-p) i=$((i+1)) continue @@ -26,9 +27,6 @@ _strace() _command_offset $offset else - COMPREPLY=() - _get_comp_words_by_ref cur prev - case $prev in -e) if [[ "$cur" == *=* ]]; then @@ -37,11 +35,12 @@ _strace() # Import arch-specific syscalls -- not foolproof IMHO #+ --David Paleino - arch=$(command uname -m) - syscalls=$(awk '/^#define __NR/ {print $2}' \ + local arch=$(command uname -m) + local syscalls=$(awk '/^#define __NR/ {print $2}' \ /usr/include/asm/unistd.h | sed -e \ 's/__NR_//') if [ -z "$syscalls" ]; then + local unistd if [[ "$arch" == *86 ]]; then unistd=/usr/include/asm/unistd_32.h else diff --git a/completions/svk b/completions/svk index 6d416be4..d60e1285 100644 --- a/completions/svk +++ b/completions/svk @@ -4,10 +4,10 @@ have svk || return _svk() { - local cur prev commands options command + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur prev + local commands options command commands='add admin annotate ann blame praise cat checkout co cleanup \ 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 \ sw sync sy update up verify' - if [[ $COMP_CWORD -eq 1 ]] ; then + if [[ $cword -eq 1 ]] ; then if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--version' -- "$cur" ) ) else @@ -36,7 +36,7 @@ _svk() ;; esac - command=${COMP_WORDS[1]} + command=${words[1]} if [[ "$cur" == -* ]]; then # possible options for the command diff --git a/completions/sysbench b/completions/sysbench index d55e6898..215ca5e2 100644 --- a/completions/sysbench +++ b/completions/sysbench @@ -8,12 +8,12 @@ have sysbench || return _sysbench() { - COMPREPLY=() - local cur prev words split=false - _get_comp_words_by_ref -n = cur prev words + local cur prev words cword + _init_completion -n = || return # long options need the "=" (whitespace split doesn't work), but we split # internally to make processing easier + local split=false _split_longopt && split=true case $prev in diff --git a/completions/sysctl b/completions/sysctl index 13a91365..880ad9db 100644 --- a/completions/sysctl +++ b/completions/sysctl @@ -4,10 +4,8 @@ have sysctl || return _sysctl() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return COMPREPLY=( $( compgen -W \ "$( PATH="$PATH:/sbin" sysctl -N -a 2>/dev/null )" -- "$cur" ) ) diff --git a/completions/sysv-rc b/completions/sysv-rc index 94ca25a0..6e480a40 100644 --- a/completions/sysv-rc +++ b/completions/sysv-rc @@ -5,9 +5,10 @@ have 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 \ || sysvdir=/etc/init.d @@ -16,14 +17,14 @@ _update_rc_d() services=( ${services[@]#$sysvdir/} ) options=( -f -n ) - if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then + if [[ $cword -eq 1 || "$prev" == -* ]]; then valid_options=( $( \ - tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \ + tr " " "\n" <<<"${words[@]} ${options[@]}" \ | sed -ne "/$( sed "s/ /\\|/g" <<<"${options[@]}" )/p" \ | sort | uniq -u \ ) ) COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \ - -X '$( tr " " "|" <<<${COMP_WORDS[@]} )' -- "$cur" ) ) + -X '$( tr " " "|" <<<${words[@]} )' -- "$cur" ) ) elif [[ "$prev" == ?($( tr " " "|" <<<${services[@]} )) ]]; then COMPREPLY=( $( compgen -W 'remove defaults start stop' -- "$cur" ) ) elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then @@ -69,9 +70,10 @@ complete -F _update_rc_d update-rc.d have 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 \ || sysvdir=/etc/init.d @@ -81,9 +83,9 @@ _invoke_rc_d() options=( --help --quiet --force --try-anyway --disclose-deny --query \ --no-fallback ) - if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then + if [[ ($cword -eq 1) || ("$prev" == --* ) ]]; then valid_options=( $( \ - tr " " "\n" <<<"${COMP_WORDS[@]} ${options[@]}" \ + tr " " "\n" <<<"${words[@]} ${options[@]}" \ | sed -ne "/$( sed "s/ /\\\\|/g" <<<"${options[@]}" )/p" \ | sort | uniq -u \ ) ) diff --git a/completions/tar b/completions/tar index 1270b262..9d875788 100644 --- a/completions/tar +++ b/completions/tar @@ -4,10 +4,10 @@ have tar || return _tar() { - local cur prev words cword ext regex tar untar + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur prev words cword + local ext regex tar untar if [ $cword -eq 1 ]; then COMPREPLY=( $( compgen -W 'c t x u r d A' -- "$cur" ) ) @@ -65,7 +65,7 @@ _tar() # complete on files in tar file # # 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 untar=t${words[1]//[^IJzjyf]/} diff --git a/completions/tcpdump b/completions/tcpdump index e4bfdd94..cfed6fab 100644 --- a/completions/tcpdump +++ b/completions/tcpdump @@ -4,10 +4,8 @@ have tcpdump || return _tcpdump() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -r|-w|-F) diff --git a/completions/unace b/completions/unace index 3083410f..17380c29 100644 --- a/completions/unace +++ b/completions/unace @@ -4,15 +4,13 @@ have unace || return _unace() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]] ; then COMPREPLY=( $( compgen -W '-c -c- -f -f- -o -o- -p -y -y-' -- "$cur" ) ) else - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then COMPREPLY=( $( compgen -W 'e l t v x' -- "$cur" ) ) else _filedir ace diff --git a/completions/unrar b/completions/unrar index e561133c..f83ef3b0 100644 --- a/completions/unrar +++ b/completions/unrar @@ -4,17 +4,15 @@ have unrar || return _unrar() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]] ; then COMPREPLY=( $( compgen -W '-ad -ap -av- -c- -cfg- -cl -cu \ -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" ) ) 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" ) ) else _filedir rar diff --git a/completions/update-alternatives b/completions/update-alternatives index a4bdf96b..5033cc54 100644 --- a/completions/update-alternatives +++ b/completions/update-alternatives @@ -9,9 +9,9 @@ _installed_alternatives() for i in alternatives dpkg/alternatives rpm/alternatives; do [ -d /var/lib/$i ] && admindir=/var/lib/$i && break done - for (( i=1; i < COMP_CWORD; i++ )); do - if [[ "${COMP_WORDS[i]}" == --admindir ]]; then - admindir=${COMP_WORDS[i+1]} + for (( i=1; i < cword; i++ )); do + if [[ "${words[i]}" == --admindir ]]; then + admindir=${words[i+1]} break fi done @@ -20,10 +20,8 @@ _installed_alternatives() _update_alternatives() { - local cur prev mode args i - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in --altdir|--admindir) @@ -35,11 +33,13 @@ _update_alternatives() ;; esac + local mode args i + # find which mode to use and how many real args used so far - for (( i=1; i < COMP_CWORD; i++ )); do - if [[ "${COMP_WORDS[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then - mode=${COMP_WORDS[i]} - args=$(($COMP_CWORD - i)) + for (( i=1; i < cword; i++ )); do + if [[ "${words[i]}" == --@(install|remove|auto|display|config|remove-all|set) ]]; then + mode=${words[i]} + args=$(($cword - i)) break fi done diff --git a/completions/util-linux b/completions/util-linux index 918363aa..72b97765 100644 --- a/completions/util-linux +++ b/completions/util-linux @@ -5,16 +5,14 @@ have renice && _renice() { - local command cur curopt i + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur - command=$1 + local command=$1 curopt i=0 - i=0 # walk back through command line and find last option - while [[ $i -le $COMP_CWORD && ${#COMPREPLY[@]} -eq 0 ]]; do - curopt=${COMP_WORDS[COMP_CWORD-$i]} + while [[ $i -le $cword && ${#COMPREPLY[@]} -eq 0 ]]; do + curopt=${words[cword-$i]} case "$curopt" in -u) _allowed_users @@ -36,12 +34,10 @@ complete -F _renice renice have kill && _kill() { - local cur + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur - - if [[ $COMP_CWORD -eq 1 && "$cur" == -* ]]; then + if [[ $cword -eq 1 && "$cur" == -* ]]; then # return list of available signals _signals else @@ -56,12 +52,10 @@ complete -F _kill kill have look && _look() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return - if [[ $COMP_CWORD -eq 1 ]]; then + if [[ $cword -eq 1 ]]; then COMPREPLY=( $( compgen -W '$(look "$cur" 2>/dev/null)' -- "$cur" ) ) fi } && diff --git a/completions/vncviewer b/completions/vncviewer index 296eb8af..dcfcab8d 100644 --- a/completions/vncviewer +++ b/completions/vncviewer @@ -20,10 +20,8 @@ complete -F _vncviewer_bootstrap vncviewer have tightvncviewer && _tightvncviewer() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -passwd) @@ -61,10 +59,8 @@ complete -F _tightvncviewer tightvncviewer have xvnc4viewer && _xvnc4viewer() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return # Convert double dash to single dash case ${prev/#--/-} in diff --git a/completions/vpnc b/completions/vpnc index 174b8f3c..9cb35b7a 100644 --- a/completions/vpnc +++ b/completions/vpnc @@ -4,10 +4,8 @@ have vpnc || return _vpnc() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in --pfs) diff --git a/completions/wireless-tools b/completions/wireless-tools index 13a82d6e..75c348ca 100644 --- a/completions/wireless-tools +++ b/completions/wireless-tools @@ -5,10 +5,8 @@ have iwconfig && _iwconfig() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in mode) @@ -20,7 +18,7 @@ _iwconfig() COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) ) if [ -n "${COMP_IWLIST_SCAN:-}" ]; then COMPREPLY+=( $( compgen -W \ - "$( iwlist ${COMP_WORDS[1]} scan | \ + "$( iwlist ${words[1]} scan | \ awk -F'\"' '/ESSID/ {print $2}' )" -- "$cur" ) ) fi return 0 @@ -30,13 +28,13 @@ _iwconfig() return 0 ;; channel) - COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \ + COMPREPLY=( $( compgen -W "$( iwlist ${words[1]} channel | \ awk '/^[ \t]*Channel/ {print $2}' )" -- "$cur" ) ) return 0 ;; freq) - COMPREPLY=( $( compgen -W "$( iwlist ${COMP_WORDS[1]} channel | \ + COMPREPLY=( $( compgen -W "$( iwlist ${words[1]} channel | \ awk '/^[ \t]*Channel/ {print $4"G"}')" -- "$cur" ) ) return 0 ;; @@ -44,7 +42,7 @@ _iwconfig() COMPREPLY=( $( compgen -W 'on off any' -- "$cur" ) ) if [ -n "${COMP_IWLIST_SCAN:-}" ]; then COMPREPLY+=( $( compgen -W \ - "$( iwlist ${COMP_WORDS[1]} scan | \ + "$( iwlist ${words[1]} scan | \ awk -F ': ' '/Address/ {print $2}' )" -- "$cur" ) ) fi return 0 @@ -52,7 +50,7 @@ _iwconfig() rate) COMPREPLY=( $( compgen -W 'auto fixed' -- "$cur" ) ) COMPREPLY+=( $( compgen -W \ - "$( iwlist ${COMP_WORDS[1]} rate | \ + "$( iwlist ${words[1]} rate | \ awk '/^[ \t]*[0-9]/ {print $1"M"}' )" -- "$cur" ) ) return 0 ;; @@ -78,7 +76,7 @@ _iwconfig() ;; esac - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) else @@ -96,12 +94,10 @@ complete -F _iwconfig iwconfig have iwlist && _iwlist() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) else @@ -119,12 +115,10 @@ complete -F _iwlist iwlist have iwspy && _iwspy() { - local cur + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur - - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) else @@ -140,10 +134,8 @@ complete -F _iwspy iwspy have iwpriv && _iwpriv() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in roam) @@ -156,7 +148,7 @@ _iwpriv() ;; esac - if [ $COMP_CWORD -eq 1 ]; then + if [ $cword -eq 1 ]; then if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--help --version' -- "$cur" ) ) else diff --git a/completions/wodim b/completions/wodim index 8ccfcd8f..4e644657 100644 --- a/completions/wodim +++ b/completions/wodim @@ -8,10 +8,10 @@ have cdrecord || have wodim || return _cdrecord() { - local cur prev i generic_options track_options track_mode + local cur prev words cword + _init_completion -n = || return - COMPREPLY=() - _get_comp_words_by_ref -n = cur prev + local i generic_options track_options track_mode # foo=bar style option if [[ "$cur" == *=* ]]; then @@ -82,7 +82,7 @@ _cdrecord() -copy -nocopy -scms isrc= index= padsize= pregap= tsize= ) # look if previous was either a file or a track option track_mode=0 - if [ $COMP_CWORD -gt 1 ]; then + if [ $cword -gt 1 ]; then if [ -f "$prev" ]; then track_mode=1 else diff --git a/completions/wol b/completions/wol index 3e663ac6..ce8e6295 100644 --- a/completions/wol +++ b/completions/wol @@ -4,9 +4,10 @@ have wol || return _wol() { - local cur prev split=false - COMPREPLY=() - _get_comp_words_by_ref -n : cur prev + local cur prev words cword + _init_completion -n : || return + + local split=false _split_longopt && split=true case $prev in diff --git a/completions/wtf b/completions/wtf index d68b6ba0..e34c7697 100644 --- a/completions/wtf +++ b/completions/wtf @@ -5,15 +5,15 @@ have wtf || return _wtf() { - local cur prev db - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return [ "$prev" = -f ] && _filedir && return 0 [[ "$cur" == -* ]] && COMPREPLY=( -f ) && return 0 - set -- "${COMP_WORDS[@]}" + local db + + set -- "${words[@]}" while [ $# -gt 0 ]; do if [ "$1" = -f ]; then shift ; db=$1 ; break diff --git a/completions/wvdial b/completions/wvdial index bc7e59bc..78ae25f2 100644 --- a/completions/wvdial +++ b/completions/wvdial @@ -4,10 +4,8 @@ have wvdial || return _wvdial() { - local cur prev config i IFS=$'\n' - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in --config) @@ -16,6 +14,8 @@ _wvdial() ;; esac + local config i IFS=$'\n' + case $cur in -*) COMPREPLY=( $( compgen -W '--config --chat \ @@ -26,9 +26,9 @@ _wvdial() # start with global and personal config files config="/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc" # replace with command line config file if present - for (( i=1; i < COMP_CWORD; i++ )); do - if [[ "${COMP_WORDS[i]}" == "--config" ]]; then - config=${COMP_WORDS[i+1]} + for (( i=1; i < cword; i++ )); do + if [[ "${words[i]}" == "--config" ]]; then + config=${words[i+1]} break fi done diff --git a/completions/xhost b/completions/xhost index 0476afe1..2cbabe86 100644 --- a/completions/xhost +++ b/completions/xhost @@ -4,8 +4,8 @@ have xhost || return _xhost () { - local cur - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return case $cur in +*) _known_hosts_real -p+ "${cur:1}" ;; diff --git a/completions/xm b/completions/xm index 1ec2cbfd..dfed9836 100644 --- a/completions/xm +++ b/completions/xm @@ -16,12 +16,12 @@ _xen_domain_ids() _xm() { - # TODO: _split_longopt + local cur prev words cword + _init_completion || return - local cur prev command options + # TODO: _split_longopt - COMPREPLY=() - _get_comp_words_by_ref cur prev + local command options commands='console vncviewer create new delete destroy domid domname \ 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 \ setpolicy resetpolicy getpolicy shell help' - if [[ $COMP_CWORD -eq 1 ]] ; then + if [[ $cword -eq 1 ]] ; then COMPREPLY=( $( compgen -W "$commands" -- "$cur" ) ) else if [[ "$cur" == *=* ]]; then @@ -42,7 +42,7 @@ _xm() cur=${cur/*=/} fi - command=${COMP_WORDS[1]} + command=${words[1]} if [[ "$cur" == -* ]]; then # possible options for the command case $command in diff --git a/completions/xmllint b/completions/xmllint index 7e832963..8095dae5 100644 --- a/completions/xmllint +++ b/completions/xmllint @@ -4,10 +4,8 @@ have xmllint || return _xmllint() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -o|--output) diff --git a/completions/xmlwf b/completions/xmlwf index 0df64043..71fbb733 100644 --- a/completions/xmlwf +++ b/completions/xmlwf @@ -4,10 +4,8 @@ have xmlwf || return _xmlwf() { - local cur prev - - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -d) diff --git a/completions/xmms b/completions/xmms index cb031dae..82473b0d 100644 --- a/completions/xmms +++ b/completions/xmms @@ -4,10 +4,8 @@ have xmms || return _xmms() { - local cur - - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '-h --help -r --rew -p --play \ diff --git a/completions/xmodmap b/completions/xmodmap index dfa67411..595b26e7 100644 --- a/completions/xmodmap +++ b/completions/xmodmap @@ -4,9 +4,8 @@ have xmodmap || return _xmodmap() { - COMPREPLY=() - local cur prev - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -display|-e) diff --git a/completions/xrandr b/completions/xrandr index b1747e63..6c929a60 100644 --- a/completions/xrandr +++ b/completions/xrandr @@ -4,9 +4,10 @@ have xrandr || return _xrandr() { - local cur prev output modes - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return + + local output modes case $prev in --output) @@ -15,9 +16,9 @@ _xrandr() return 0 ;; --mode) - for(( i = 1; i < COMP_CWORD; i++ )); do - if [[ "${COMP_WORDS[i]}" == "--output" ]]; then - output=${COMP_WORDS[i+1]} + for(( i = 1; i < cword; i++ )); do + if [[ "${words[i]}" == "--output" ]]; then + output=${words[i+1]} break fi done diff --git a/completions/xrdb b/completions/xrdb index 77d68892..b42320fe 100644 --- a/completions/xrdb +++ b/completions/xrdb @@ -4,9 +4,8 @@ have xrdb || return _xrdb() { - COMPREPLY=() - local cur prev - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in -backup|-display|-help) diff --git a/completions/xsltproc b/completions/xsltproc index 6b837c0e..32efcab4 100644 --- a/completions/xsltproc +++ b/completions/xsltproc @@ -4,9 +4,8 @@ have xsltproc || return _xsltproc() { - local cur prev - COMPREPLY=() - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return case $prev in --output|-o) @@ -37,7 +36,7 @@ _xsltproc() ;; esac - [[ $COMP_CWORD -gt 2 && `_get_cword '' 2` == --?(string)param ]] && \ + [[ $cword -gt 2 && `_get_cword '' 2` == --?(string)param ]] && \ return 0 if [[ "$cur" == -* ]]; then diff --git a/completions/xz b/completions/xz index 45fc0d35..8a4fc5e3 100644 --- a/completions/xz +++ b/completions/xz @@ -3,9 +3,8 @@ have xz || have pxz && _xz() { - COMPREPLY=() - local cur prev - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--compress --decompress --test --list \ @@ -64,9 +63,8 @@ complete -F _xz xz pxz have xzdec && _xzdec() { - COMPREPLY=() - local cur prev - _get_comp_words_by_ref cur prev + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]]; then COMPREPLY=( $( compgen -W '--memory --quiet --help --version' \ diff --git a/completions/yp-tools b/completions/yp-tools index 856c2c26..f777a5b0 100644 --- a/completions/yp-tools +++ b/completions/yp-tools @@ -4,22 +4,20 @@ have ypcat || return _ypmatch() { - local cur map cmd + local cur prev words cword + _init_completion || return - COMPREPLY=() - _get_comp_words_by_ref cur - cmd=${1##*/} + local map cmd=${1##*/} - [[ $cmd == ypcat && $COMP_CWORD -gt 1 ]] && return 0 - [[ $cmd == ypmatch && $COMP_CWORD -gt 2 ]] && return 0 + [[ $cmd == ypcat && $cword -gt 1 ]] && return 0 + [[ $cmd == ypmatch && $cword -gt 2 ]] && return 0 - if [[ $cmd == ypmatch && $COMP_CWORD -eq 1 && \ - ${#COMP_WORDS[@]} -eq 3 ]]; then - map=${COMP_WORDS[2]} + if [[ $cmd == ypmatch && $cword -eq 1 && ${#words[@]} -eq 3 ]]; then + map=${words[2]} COMPREPLY=( $( compgen -W '$( ypcat $map | \ cut -d':' -f 1 )' -- "$cur") ) else - [[ $cmd == ypmatch && $COMP_CWORD -ne 2 ]] && return 0 + [[ $cmd == ypmatch && $cword -ne 2 ]] && return 0 COMPREPLY=( $( compgen -W \ '$( printf "%s\n" $(ypcat -x | cut -d"\"" -f 2) )' -- "$cur")) fi diff --git a/completions/yum-arch b/completions/yum-arch index 7fc5ed32..eb02b924 100644 --- a/completions/yum-arch +++ b/completions/yum-arch @@ -4,9 +4,8 @@ have yum-arch || return _yum_arch() { - local cur - COMPREPLY=() - _get_comp_words_by_ref cur + local cur prev words cword + _init_completion || return if [[ "$cur" == -* ]] ; then COMPREPLY=( $( compgen -W '-d -v -vv -n -c -z -s -l -q' -- "$cur" ) ) |