[Bash-completion-devel] completion for ipv6calc

gibboris at gmail.com gibboris at gmail.com
Sun Jan 3 20:23:11 UTC 2010


> have ipv6calc &&
> _ipv6calc()
> {
>     local cur prev split=false
> 
>     COMPREPLY=()
>     cur=`_get_cword =`
>     prev=`_get_pword`
> 
>     _split_longopt && split=true
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.

> 
>     case "$prev" in
>         -I|--in)
>             COMPREPLY=( $( compgen -W 'auto revnibbles.int \
>                 revnibbles.arpa bitstring ipv6addr ipv4addr mac \
>                 base85 ifinet6 iid+token ipv6logconv prefix+mac' \
>                 -- "$cur" ) )
>             return 0
>             ;;
>         -O|--out)
>             COMPREPLY=( $( compgen -W 'revnibbles.int \
>                 revnibbles.arpa bitstring ipv6addr ipv4addr mac \
>                 eui64 base85 ifinet6 iid iid+token addrtype \
>                 ouitype ipv6addrtype any revipv4' -- "$cur" ) )
>             return 0
>             ;;
>         -A|--action)
>             COMPREPLY=( $( compgen -W 'auto geneui64 conv6to4 \
>                 genprivacyiid prefixmac2ipv6' -- "$cur" ) )
>             return 0
>             ;;
>     esac
> 
>     $split && return 0
> 

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 :)

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&content-type=text/vnd.viewcvs-markup)
[ here (programs with compile-time features/help-output) is the power of _longopt ]

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)

I wish I'm not too nitpicking.

Raph



More information about the Bash-completion-devel mailing list