Various postfix completion improvements.

This commit is contained in:
Ville Skyttä 2009-05-21 11:52:58 +03:00
parent 29c9fc3df8
commit cc66ec76f5
2 changed files with 117 additions and 85 deletions

View File

@ -49,6 +49,7 @@ bash-completion (1.x)
* Fix leaking $prev from cpio, dsniff, freeciv, gkrellm, mkinitrd, and * Fix leaking $prev from cpio, dsniff, freeciv, gkrellm, mkinitrd, and
tcpdump completions. tcpdump completions.
* Split ant completion to contrib/ant, improve the built in one. * Split ant completion to contrib/ant, improve the built in one.
* Improve postfix completion.
[ Todd Zullinger ] [ Todd Zullinger ]
* Make yum complete on filenames after install, deplist, update and upgrade * Make yum complete on filenames after install, deplist, update and upgrade

View File

@ -10,25 +10,30 @@ _postfix()
{ {
local cur prev local cur prev
COMPREPLY=()
cur=`_get_cword` cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $cur == '-' ]]; then case $prev in
COMPREPLY=(-c -D -v) -c)
_filedir -d
return 0
;;
-D)
COMPREPLY=( $( compgen -W 'start' -- $cur ) )
return 0
;;
esac
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-c -D -v' -- $cur ) )
return 0 return 0
fi fi
if [[ $prev == '-c' ]]; then
_filedir -d COMPREPLY=( $( compgen -W 'check start stop abort flush reload status \
return 0 set-permissions upgrade-configuration' -- $cur ) )
fi
if [[ $prev == '-D' ]]; then
COMPREPLY=( $( compgen -W 'start' -- "`_get_cword`" ) )
return 0
fi
COMPREPLY=( $( compgen -W 'start stop reload abort flush check' -- \
"`_get_cword`" ) )
} }
complete -F _postfix postfix complete -F _postfix $filenames postfix
# postalias(1) and postmap(1) # postalias(1) and postmap(1)
# #
@ -36,18 +41,23 @@ _postmap()
{ {
local cur prev len idx local cur prev len idx
COMPREPLY=()
cur=`_get_cword` cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $cur == '-' ]]; then case $prev in
COMPREPLY=(-N -f -i -n -o -p -r -v -w -c -d -q) -c)
return 0 _filedir -d
fi return 0
if [[ $prev == '-c' ]]; then ;;
_filedir -d -[dq])
return 0 return 0
fi ;;
if [[ $prev == -[dq] ]]; then esac
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-N -f -i -n -o -p -r -v -w -c -d -q'\
-- $cur ) )
return 0 return 0
fi fi
@ -68,7 +78,7 @@ _postmap()
fi fi
return 0 return 0
} }
complete -F _postmap postmap postalias complete -F _postmap $filenames postmap postalias
# postcat(1) # postcat(1)
# #
@ -76,15 +86,19 @@ _postcat()
{ {
local cur prev pval len idx qfile local cur prev pval len idx qfile
COMPREPLY=()
cur=`_get_cword` cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $cur == '-' ]]; then case $prev in
COMPREPLY=(-c -q -v) -c)
return 0 _filedir -d
fi return 0
if [[ $prev == '-c' ]]; then ;;
_filedir -d esac
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-c -q -v' -- $cur ) )
return 0 return 0
fi fi
@ -95,7 +109,7 @@ _postcat()
if [[ $qfile == 1 ]]; then if [[ $qfile == 1 ]]; then
len=${#cur} len=${#cur}
idx=0 idx=0
for pval in $( mailq | \ for pval in $( mailq 2>/dev/null | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval COMPREPLY[$idx]=$pval
@ -108,7 +122,7 @@ _postcat()
return 0 return 0
fi fi
} }
complete -F _postcat postcat complete -F _postcat $filenames postcat
# postconf(1) # postconf(1)
# #
@ -116,23 +130,34 @@ _postconf()
{ {
local cur prev pval len idx eqext local cur prev pval len idx eqext
COMPREPLY=()
cur=`_get_cword` cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $cur == '-' ]]; then
COMPREPLY=(-c -d -e -h -m -l -n -v) case $prev in
-b|-t)
_filedir
return 0
;;
-c)
_filedir -d
return 0
;;
-e)
cur=${cur#[\"\']}
eqext='='
;;
esac
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-A -a -b -c -d -e -h -m -l -n -t -v'\
-- $cur ) )
return 0 return 0
fi fi
if [[ $prev == '-c' ]]; then
_filedir -d
return 0
fi
if [[ $prev == '-e' ]]; then
cur=${cur#[\"\']}
eqext='='
fi
len=${#cur} len=${#cur}
idx=0 idx=0
for pval in $( /usr/sbin/postconf | 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"
idx=$(($idx+1)) idx=$(($idx+1))
@ -140,7 +165,7 @@ _postconf()
done done
return 0 return 0
} }
complete -F _postconf postconf complete -F _postconf $filenames postconf
# postsuper(1) # postsuper(1)
# #
@ -148,53 +173,59 @@ _postsuper()
{ {
local cur prev pval len idx local cur prev pval len idx
COMPREPLY=()
cur=`_get_cword` cur=`_get_cword`
prev=${COMP_WORDS[COMP_CWORD-1]} prev=${COMP_WORDS[COMP_CWORD-1]}
if [[ $cur == '-' ]]; then case $prev in
COMPREPLY=(-c -d -h -H -p -r -s -v) -c)
_filedir -d
return 0
;;
-[dr])
len=${#cur}
idx=0
for pval in $( echo ALL; mailq 2>/dev/null | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval
idx=$(($idx+1))
fi
done
return 0
;;
-h)
len=${#cur}
idx=0
for pval in $( echo ALL; mailq 2>/dev/null | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval
idx=$(($idx+1))
fi
done
return 0
;;
-H)
len=${#cur}
idx=0
for pval in $( echo ALL; mailq 2>/dev/null | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval
idx=$(($idx+1))
fi
done
return 0
;;
esac
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '-c -d -h -H -p -r -s -v' -- $cur ) )
return 0 return 0
fi fi
case $prev in
-[dr])
len=${#cur}
idx=0
for pval in $( echo ALL; mailq | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* !].*$//' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval
idx=$(($idx+1))
fi
done
return 0
;;
-h)
len=${#cur}
idx=0
for pval in $( echo ALL; mailq | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; s/[* ].*$//; /!$/d' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval
idx=$(($idx+1))
fi
done
return 0
;;
-H)
len=${#cur}
idx=0
for pval in $( echo ALL; mailq | \
sed -e '1d; $d; /^[^0-9A-Z]\|^$/d; /^[0-9A-Z]*[* ]/d; s/!.*$//' ); do
if [[ "$cur" == "${pval:0:$len}" ]]; then
COMPREPLY[$idx]=$pval
idx=$(($idx+1))
fi
done
return 0
;;
esac
COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) ) COMPREPLY=( $( compgen -W 'hold incoming active deferred' -- $cur ) )
return 0
} }
complete -F _postsuper postsuper complete -F _postsuper $filenames postsuper
} }