[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-151-g1709686
Ville Skyttä
ville.skytta at iki.fi
Thu Apr 28 18:46:07 UTC 2011
The following commit has been merged in the master branch:
commit d5454732d8a14e3e6da07383243f92e1c23e5913
Author: Ville Skyttä <ville.skytta at iki.fi>
Date: Thu Apr 28 21:35:08 2011 +0300
getent: Allow multiple completions from same db, add option completion.
diff --git a/completions/getent b/completions/getent
index 5b723fa..d51383f 100644
--- a/completions/getent
+++ b/completions/getent
@@ -5,9 +5,31 @@ have getent || return
_getent()
{
local cur prev words cword
- _init_completion || return
+ _init_completion -n = || return
- case $prev in
+ local split=false
+ _split_longopt && split=true
+
+ local i db
+ for (( i=1; i < cword; i++ )); do
+ case ${words[i]} in
+ -V|--version|--usage|-'?'|--help)
+ return
+ ;;
+ -s|--service)
+ (( i++ ))
+ ;;
+ -*)
+ ;;
+ *)
+ # First non-option value is the db
+ db=${words[i]}
+ break
+ ;;
+ esac
+ done
+
+ case $db in
passwd)
COMPREPLY=( $( compgen -u "$cur" ) )
return 0
@@ -25,19 +47,31 @@ _getent()
return 0
;;
protocols|networks|ahosts|ahostsv4|ahostsv6|rpc)
- COMPREPLY=( $( compgen -W "$( getent "$prev" | \
+ COMPREPLY=( $( compgen -W "$( getent $db | \
awk '{ print $1 }' )" -- "$cur" ) )
return 0
;;
aliases|shadow|gshadow)
- COMPREPLY=( $( compgen -W "$( getent "$prev" | cut -d: -f1 )" \
+ COMPREPLY=( $( compgen -W "$( getent $db | cut -d: -f1 )" \
-- "$cur" ) )
return 0
;;
+ ethers|netgroup)
+ return
+ ;;
+ esac
+
+ case $prev in
+ -s|--service)
+ return
+ ;;
esac
+ $split && return
- if [ $cword -eq 1 ]; then
+ if [[ $cur == -* ]]; then
+ COMPREPLY=( $( compgen -W '$( _parse_help "$1" )' -- "$cur" ) )
+ elif [[ -z $db ]]; then
COMPREPLY=( $( compgen -W 'passwd group hosts services protocols \
networks ahosts ahostsv4 ahostsv6 aliases ethers netgroup rpc \
shadow gshadow' -- "$cur" ) )
--
bash-completion
More information about the Bash-completion-commits
mailing list