Hello,
I just tried a first attempt for the wget completion (see attachement).
(it's also my first completion)

- case statements are not yet "optimised".
- don't know how to specifically set a COMPREPLY as an option which
  requires a parameter (want to see "=" appended to the option list)
  A solution would be to append '=' to theses options in $cur case
  and use --option=) in $prev case, but maybe a cleaner solution exists ?
- long option where a short option exists are not given in the
  completion of long options ([ [:blank:]]), why ?
  Don't know myself, but I ""feel"" I should handle them separatly.
- any way to complete (or at least to give a clue about the value
  expected) for an option waiting for a numeric parameter ?
  This question joins the above one about appending a '=' to parametered
  options.
- doubts about completion of main argument, ideas :
  "f" --> "tp://"
  "h" --> "ttp"
  "http" --> "s://" | "://"
  "w" | "http://w"; | "https://w"; --> "www."
- completing -O, --output-document, --output-file, and -o
  make overwriting easier ... should they be implemented ?
Will continue soon, but I first would like any
comment/advice/criticism/whatever.

Raph
# wget(1) completion
# Copyright 2009 Droz Raphaël <[email protected]>
# License: GNU GPL v2 or later
#
# $Id: wget,v 0.1 2009/03/13 19:35:22 r4ph Exp $

_wget()
{
    local cur prev

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}
    
    case "$prev" in
        --progress)
            COMPREPLY=( $( compgen -W 'bar dot' -- $cur ) )
            return 0
            ;;
        --bind-address|--exclude-domains|--domains|-D)
            _known_hosts
            return 0
            ;;
        --restrict-file-names)
            COMPREPLY=( $( compgen -W 'unix windows' -- $cur ) )
            #todo : ,nocontrol
            return 0
            ;;
        --prefer-family)
            COMPREPLY=( $( compgen -W 'IPv4 IPv6 none' -- $cur ) )
            return 0
            ;;
        --directory-prefix|--ca-directory|-P)
            _filedir -d
            return 0
            ;;
        
--load-cookies|--save-cookies|--post-file|--certificate|--ca-certificate|--private-key|--random-file|--egd-file|--append-output|-a)
            _filedir
            return 0
            ;;
        --input-file|-i)
            _filedir && COMPREPLY=( "${comprep...@]}" - )
            return 0
            ;;
        --secure-protocol)
            COMPREPLY=( $( compgen -W 'auto SSLv2 SSLv3 TLSv1' -- $cur ) )
            return 0
            ;;
        --certificate-type|--private-key-type)
            COMPREPLY=( $( compgen -W 'PEM DER' -- $cur ) )
            return 0
            ;;
        --follow-tags|--ignore-tags)
             COMPREPLY=( $( compgen -W 'a abbr acronym address applet area b 
base basefont bdo big blockquote \
                        body br button caption center cite code col colgroup dd 
del dir div dfn dl dt em fieldset \
                        font form frame frameset h6 head hr html i iframe img 
input ins isindex kbd label legend \
                        li link map menu meta noframes noscript object ol 
optgroup option p param pre q s samp \
                        script select small span strike strong style sub sup 
table tbody td textarea tfoot th \
                        thead title tr tt u ul var xmp' -- $cur ) )
             return 0
             ;;
             #TODO : long options with a parameter not defined above
    esac

    case "$cur" in
        --*)
            #parametered ones first (only those defined above)
            #then long non-parametered ones
            COMPREPLY=( $( compgen -W "--progress --bind-address 
--restrict-file-names --prefer-family --directory-prefix \
            --load-cookies --save-cookies --post-file --certificate 
--ca-certificate --private-key --random-file \
            --egd-file --secure-protocol --append-output --input-file \
            --certificate-type --private-key-type --ca-directory 
--exclude-domains --domains --follow-tags --ignore-tags \
            \
            $(wget -h | sed -n 's/^[ [:blank:]]*\(--[a-z-]*\)[ 
[:blank:]].*$/\1/Ip')" -- $cur ) )
            return 0
            ;;
        -*)
            COMPREPLY=( $( compgen -W "$(wget -h | sed -n 's/^[ 
[:blank:]]*\(-[a-z46]\).*$/\1/Ip')" -- $cur ) )
            return 0
            ;;
        #*)
        #    COMPREPLY=( $( compgen -W 'http:// https:// ftp:// ftp:// file://' 
-- $cur ) )
        #    return 0
        #    ;;
    esac

    return 0
}
complete -F _wget -o default wget
_______________________________________________
Bash-completion-devel mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/bash-completion-devel

Reply via email to