Use _init_completion() in completions/p*.

This commit is contained in:
Ville Skyttä 2011-04-20 23:08:37 +03:00
parent aef53c1160
commit e3ca91b986
14 changed files with 85 additions and 104 deletions

View File

@ -4,10 +4,10 @@ have p4 || return
_p4() _p4()
{ {
local cur prev words cword p4commands p4filetypes local cur prev words cword
_init_completion || return
COMPREPLY=() local p4commands p4filetypes
_get_comp_words_by_ref cur prev words cword
# rename isn't really a command # rename isn't really a command
p4commands="$( p4 help commands | awk 'NF>3 {print $1}' )" p4commands="$( p4 help commands | awk 'NF>3 {print $1}' )"

View File

@ -19,12 +19,10 @@ _perlfunctions()
_perl() _perl()
{ {
local cur prev prefix temp local cur prev words cword
local optPrefix optSuffix _init_completion -n : || return
COMPREPLY=() local prefix="" temp optPrefix optSuffix
_get_comp_words_by_ref -n : cur prev
prefix=""
# If option not followed by whitespace, reassign prev and cur # If option not followed by whitespace, reassign prev and cur
if [[ "$cur" == -?* ]]; then if [[ "$cur" == -?* ]]; then
@ -87,11 +85,10 @@ complete -F _perl perl
_perldoc() _perldoc()
{ {
local cur prev prefix temp local cur prev words cword
_init_completion -n : || return
COMPREPLY=() local prefix="" temp
_get_comp_words_by_ref -n : cur prev
prefix=""
# 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

@ -4,10 +4,8 @@ have pine || have alpine || return
_pineaddr() _pineaddr()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook \ COMPREPLY=( $( compgen -W '$( awk "{print \$1}" ~/.addressbook \
2>/dev/null)' -- "$cur" ) ) 2>/dev/null)' -- "$cur" ) )

View File

@ -4,11 +4,10 @@ have pkg-config || return
_pkg_config() _pkg_config()
{ {
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 @@
_pkg_delete() _pkg_delete()
{ {
local cur pkgdir prev local cur prev words cword
_init_completion || return
pkgdir=${PKG_DBDIR:-/var/db/pkg}/ local pkgdir=${PKG_DBDIR:-/var/db/pkg}/
_get_comp_words_by_ref cur prev
[[ "$prev" == -o || "$prev" == -p || "$prev" == -W ]] && return 0 [[ "$prev" == -o || "$prev" == -p || "$prev" == -W ]] && return 0

View File

@ -4,10 +4,8 @@
_removepkg() _removepkg()
{ {
local packages cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) ) COMPREPLY=( $( (cd /var/log/packages; compgen -f -- "$cur") ) )
} && } &&

View File

@ -3,8 +3,9 @@
have pm-is-supported && have pm-is-supported &&
_pm_is_supported() _pm_is_supported()
{ {
local cur local cur prev words cword
_get_comp_words_by_ref cur _init_completion || return
COMPREPLY=( $( compgen -W '--help --suspend --hibernate --suspend-hybrid' \ COMPREPLY=( $( compgen -W '--help --suspend --hibernate --suspend-hybrid' \
-- "$cur" ) ) -- "$cur" ) )
} && } &&
@ -13,8 +14,9 @@ complete -F _pm_is_supported pm-is-supported
have pm-hibernate || have pm-suspend || have pm-suspend-hybrid && have pm-hibernate || have pm-suspend || have pm-suspend-hybrid &&
_pm_action() _pm_action()
{ {
local cur local cur prev words cword
_get_comp_words_by_ref cur _init_completion || return
COMPREPLY=( $( compgen -W "--help $( _parse_help "$1" )" -- "$cur" ) ) COMPREPLY=( $( compgen -W "--help $( _parse_help "$1" )" -- "$cur" ) )
} && } &&
complete -F _pm_action pm-hibernate pm-suspend pm-suspend-hybrid complete -F _pm_action pm-hibernate pm-suspend pm-suspend-hybrid
@ -22,8 +24,9 @@ complete -F _pm_action pm-hibernate pm-suspend pm-suspend-hybrid
have pm-powersave && have pm-powersave &&
_pm_powersave() _pm_powersave()
{ {
local cur local cur prev words cword
_get_comp_words_by_ref cur _init_completion || return
COMPREPLY=( $( compgen -W "true false" -- "$cur" ) ) COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
} && } &&
complete -F _pm_powersave pm-powersave complete -F _pm_powersave pm-powersave

View File

@ -3,13 +3,13 @@
have portupgrade && have portupgrade &&
_portupgrade() _portupgrade()
{ {
local cur pkgdir prev local cur prev words cword
_init_completion || return
pkgdir=${PKG_DBDIR:-/var/db/pkg}/
_get_comp_words_by_ref cur prev
[[ "$prev" == -l || "$prev" == -L || "$prev" == -o ]] && return 0 [[ "$prev" == -l || "$prev" == -L || "$prev" == -o ]] && return 0
local pkgdir=${PKG_DBDIR:-/var/db/pkg}/
COMPREPLY=( $( compgen -d "$pkgdir$cur" ) ) COMPREPLY=( $( compgen -d "$pkgdir$cur" ) )
COMPREPLY=( ${COMPREPLY[@]#$pkgdir} ) COMPREPLY=( ${COMPREPLY[@]#$pkgdir} )
COMPREPLY=( ${COMPREPLY[@]%-*} ) COMPREPLY=( ${COMPREPLY[@]%-*} )
@ -21,7 +21,10 @@ complete -F _portupgrade -o dirnames portupgrade
have portinstall && have portinstall &&
_portinstall() _portinstall()
{ {
local cur portsdir prev indexfile local cur prev words cword
_init_completion || return
local portsdir indexfile
local -a COMPREPLY2 local -a COMPREPLY2
portsdir=${PORTSDIR:-/usr/ports}/ portsdir=${PORTSDIR:-/usr/ports}/

View File

@ -6,10 +6,8 @@ have postfix || return
# #
_postfix() _postfix()
{ {
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
-c) -c)
@ -36,10 +34,8 @@ complete -F _postfix postfix
# #
_postmap() _postmap()
{ {
local cur prev len idx local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-c) -c)
@ -61,8 +57,7 @@ _postmap()
_compopt_o_filenames _compopt_o_filenames
COMPREPLY=( $( compgen -f -- "${cur#*:}" ) ) COMPREPLY=( $( compgen -f -- "${cur#*:}" ) )
else else
len=${#cur} local len=${#cur} idx=0 pval
idx=0
for pval in $( /usr/sbin/postconf -m ); do for pval in $( /usr/sbin/postconf -m ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]="$pval:" COMPREPLY[$idx]="$pval:"
@ -82,10 +77,8 @@ complete -F _postmap postmap postalias
# #
_postcat() _postcat()
{ {
local cur prev pval len idx qfile local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-c) -c)
@ -99,12 +92,12 @@ _postcat()
return 0 return 0
fi fi
qfile=0 local idx qfile=0
for idx in "${COMP_WORDS[@]}"; do for idx in "${words[@]}"; do
[[ "$idx" = -q ]] && qfile=1 && break [[ "$idx" = -q ]] && qfile=1 && break
done done
if [[ $qfile -eq 1 ]]; then if [[ $qfile -eq 1 ]]; then
len=${#cur} local len=${#cur} pval
idx=0 idx=0
for pval in $( mailq 2>/dev/null | \ for pval in $( mailq 2>/dev/null | \
sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//' ); do sed -e '1d; $d; /^[^0-9A-Z]/d; /^$/d; s/[* !].*$//' ); do
@ -125,10 +118,10 @@ complete -F _postcat postcat
# #
_postconf() _postconf()
{ {
local cur prev pval len idx eqext local cur prev words cword
_init_completion || return
COMPREPLY=() local eqext
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-b|-t) -b|-t)
@ -151,8 +144,7 @@ _postconf()
return 0 return 0
fi fi
len=${#cur} local len=${#cur} idx=0 pval
idx=0
for pval in $( /usr/sbin/postconf 2>/dev/null | cut -d ' ' -f 1 ); do for pval in $( /usr/sbin/postconf 2>/dev/null | cut -d ' ' -f 1 ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]="$pval$eqext" COMPREPLY[$idx]="$pval$eqext"
@ -167,10 +159,10 @@ complete -F _postconf postconf
# #
_postsuper() _postsuper()
{ {
local cur prev pval len idx local cur prev words cword
_init_completion || return
COMPREPLY=() local pval len idx
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-c) -c)

View File

@ -22,11 +22,10 @@ _pg_users()
# #
_createdb() _createdb()
{ {
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
@ -64,11 +63,10 @@ complete -F _createdb -o default createdb
# #
_dropdb() _dropdb()
{ {
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 _dropdb -o default dropdb
# #
_psql() _psql()
{ {
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,11 +4,11 @@ have povray || have xpovray || have spovray || return
_povray() _povray()
{ {
local cur prev povcur pfx oext defoext local cur prev words cword
defoext=png # default output extension, if cannot be determined FIXME _init_completion || return
COMPREPLY=() local povcur=$cur pfx oext defoext
_get_comp_words_by_ref -c povcur prev defoext=png # default output extension, if cannot be determined FIXME
_expand || return 0 _expand || return 0
@ -22,14 +22,14 @@ _povray()
;; ;;
[-+]O*) [-+]O*)
# guess what output file type user may want # guess what output file type user may want
case $( ( IFS=$'\n'; command grep '^[-+]F' <<<"${COMP_WORDS[*]}" ) ) in case $( ( IFS=$'\n'; command grep '^[-+]F' <<<"${words[*]}" ) ) in
[-+]FN) oext=png ;; [-+]FN) oext=png ;;
[-+]FP) oext=ppm ;; [-+]FP) oext=ppm ;;
[-+]F[CT]) oext=tga ;; [-+]F[CT]) oext=tga ;;
*) oext=$defoext ;; *) oext=$defoext ;;
esac esac
# complete filename corresponding to previously specified +I # complete filename corresponding to previously specified +I
COMPREPLY=( $( ( IFS=$'\n'; command grep '^[-+]I' <<<"${COMP_WORDS[*]}" ) ) ) COMPREPLY=( $( ( IFS=$'\n'; command grep '^[-+]I' <<<"${words[*]}" ) ) )
COMPREPLY=( ${COMPREPLY[@]#[-+]I} ) COMPREPLY=( ${COMPREPLY[@]#[-+]I} )
COMPREPLY=( ${COMPREPLY[@]/%.pov/.$oext} ) COMPREPLY=( ${COMPREPLY[@]/%.pov/.$oext} )
cur="${povcur#[-+]O}" # to confuse _filedir cur="${povcur#[-+]O}" # to confuse _filedir
@ -49,7 +49,6 @@ _povray()
return 0 return 0
;; ;;
*) *)
cur="$povcur"
_filedir '@(ini|pov)' _filedir '@(ini|pov)'
return 0 return 0
;; ;;

View File

@ -5,12 +5,10 @@
[[ $UNAME == Linux || $UNAME == FreeBSD ]] || have pkill && [[ $UNAME == Linux || $UNAME == FreeBSD ]] || have pkill &&
_killall() _killall()
{ {
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
_signals _signals
else else
_pnames _pnames
@ -26,10 +24,8 @@ have pkill && complete -F _killall pkill
[ $UNAME = Linux ] || have pgrep && [ $UNAME = Linux ] || have pgrep &&
_pgrep() _pgrep()
{ {
local cur local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur
_pnames _pnames

View File

@ -50,10 +50,10 @@ _puppet_references()
_puppet() _puppet()
{ {
local cur prev xspec helpopts command subcommand local cur prev words cword
_init_completion || return
COMPREPLY=() local xspec helpopts command subcommand
_get_comp_words_by_ref cur prev
case $prev in case $prev in
--help) --help)
@ -61,7 +61,7 @@ _puppet()
;; ;;
esac esac
case ${COMP_WORDS[0]} in case ${words[0]} in
puppetmasterd) puppetmasterd)
command=master command=master
;; ;;
@ -90,9 +90,9 @@ _puppet()
command=describe command=describe
;; ;;
puppet) puppet)
case ${COMP_WORDS[1]} in case ${words[1]} in
agent|apply|cert|describe|doc|filebucket|kick|master|queue|resource) agent|apply|cert|describe|doc|filebucket|kick|master|queue|resource)
command=${COMP_WORDS[1]} command=${words[1]}
;; ;;
*.pp|*.rb|-*) *.pp|*.rb|-*)
command=apply command=apply

View File

@ -4,10 +4,8 @@ have python || return
_python() _python()
{ {
local prev cur i local cur prev words cword
_init_completion || return
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in case $prev in
-'?'|-h|--help|-V|--version|-c|-m) -'?'|-h|--help|-V|--version|-c|-m)
@ -23,15 +21,16 @@ _python()
return 0 return 0
;; ;;
!(?(*/)python*([0-9.])|-?)) !(?(*/)python*([0-9.])|-?))
[[ $COMP_CWORD -lt 2 || ${COMP_WORDS[COMP_CWORD-2]} != -@(Q|W) ]] \ [[ $cword -lt 2 || ${words[cword-2]} != -@(Q|W) ]] \
&& _filedir && _filedir
;; ;;
esac esac
# if '-c' is already given, complete all kind of files. # if '-c' is already given, complete all kind of files.
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do local i
if [[ ${COMP_WORDS[i]} == -c ]]; then for (( i=0; i < ${#words[@]}-1; i++ )); do
if [[ ${words[i]} == -c ]]; then
_filedir _filedir
fi fi
done done