[Bash-completion-devel] completion for ipv6calc
Adrian Friedli
adi at koalatux.ch
Wed Jan 6 10:40:38 UTC 2010
Hallo
On Sunday 03 January 2010 21:23:11 gibboris at gmail.com wrote:
> I was not thinking about that (sorry if I confused you)
> _split_longopt aims to ease the use of $prev and AFAIK especially in the
> case where --in=blah has to be used.
> But I don't know enough about the use of this function to push any advise
> here.
Ok, --in=blah is usable in ipv6calc too.
> but in the previous email I was thinking about replacing the following :
> > COMPREPLY=( $( compgen -W '--help --quiet --in --out --action \
> > --examples --showinfo --lowercase --uppercase \
> > --printprefix --printsuffix --maskprefix --masksuffix \
> > --printcompressed --printuncompressed \
> > --printfulluncompressed' -- "$cur" ) )
>
> by :
> [[ "$cur" == -* ]] && _longopt ipv6calc
>
> BUT after a quick look at the ipv6calc --help 2>&1 output it
> seems it's not well enough formatted to permit this kind of
> automation. (some options are not documented in --help, or several
> different are on the same line what's not currently handled by _longopt)
> so ... forget all about what I said :)
Yes, _longopt gives for ipv6calc only 11 options. But I found a way to get a
list of options for --in, --out and --action automatically.
> Exception that :
> 1) some options are missing anyway (I repeat I don't know the program nor I
> use ipv6 ;) : --machine_readable, --show_types, --db-geoip, --printstart,
> --printend, --db-ip2location-ipv4 --db-ip2location-ipv6,
> --db-geoip-default
> (http://cvs.deepspace6.net/view/ipv6calc/lib/ipv6calchelp.c?rev=1.17&conten
> t-type=text/vnd.viewcvs-markup) [ here (programs with compile-time
> features/help-output) is the power of _longopt ]
I included all the options I could find, altough not all of them are enabled
in the Debian package of ipv6calc.
> 2) IMHO the long-options COMPREPLY should happen if [[ "$cur" == -* ]]
> 3) so no completion happens otherwise (return 0) (as it seems like input
> files aren't accepted arguments)
OK.
Cheers, Adi
-------------- next part --------------
have ipv6calc &&
_ipv6calc()
{
local cur prev split=false
COMPREPLY=()
cur=`_get_cword =`
prev=`_get_pword`
_split_longopt && split=true
case "$prev" in
-d|--debug)
return 0
;;
-I|--in|-O|--out|-A|--action)
COMPREPLY=( $( compgen -W "$( ipv6calc -m "$prev" -h \
2>&1 )" -- "$cur" ) )
return 0
;;
--db-geoip|--db-ip2location-ipv4|--db-ip2location-ipv6)
_filedir
return 0
;;
--printstart|--printend)
return 0
;;
esac
$split && return 0
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '--help --debug --quiet --in \
--out --action --examples --showinfo --show_types \
--machine_readable --db-geoip --db-geoip-default \
--db-ip2location-ipv4 --db-ip2location-ipv6 \
--lowercase --uppercase --printprefix --printsuffix \
--maskprefix --masksuffix --printstart --printend \
--printcompressed --printuncompressed \
--printfulluncompressed --printmirrored' -- "$cur" ) )
return 0
fi
return 0
} &&
complete -F _ipv6calc ipv6calc
# ex: ts=4 sw=4 et filetype=sh
More information about the Bash-completion-devel
mailing list