Ainsi parlait Han :
> Guillaume Rousse ([EMAIL PROTECTED]) wrote:
> > Well, that was only a first quick try :-) I'll try harder.
>
> I included you're urpmi completion as well. But if you tried with more
> succes ;) please lemme know, and I will bake a -4mdk.
Here is a better one, tough still not able to compete with zsh :-)
I submitted it to bash_completion file maintainer, off course, but until it 
get merged, could you add it as a distinct patch ? Thanks. 

# Mandrake urpmi functions
#
have urpmi &&
_urpmi.medias()
{
        # return list of available urpmi medias
        COMPREPLY=( $( cat /etc/urpmi/urpmi.cfg | awk '/{/ {print $1}' | grep ^$cur 
) )

}
have urpmi &&
_urpmi()
{
        COMPREPLY=()
        local cur prev

        cur=${COMP_WORDS[COMP_CWORD]}
        prev=${COMP_WORDS[COMP_CWORD-1]}

        case $prev in
                --media)
                        _urpmi.medias
                        return 0;;
        esac

        if [[ "$cur" == -* ]]; then
                # return list of available options
                COMPREPLY=( $( compgen -W '--help --update --media --auto \
                --auto-select --complete --force --wget --curl --X \
                --best-output -a -p -q -v' | grep ^$cur ) )
        else
                # return list of available packages
                COMPREPLY=( $( gzip -dc /var/lib/urpmi/synthesis.hdlist.* \
                | awk 'BEGIN {FS="@"} /info/ {print $1}' | grep ^$cur ) )
        fi

}
[ "$have" ] && complete -F _urpmi urpmi
have urpmi.update &&
_urpmi.update()
{
        COMPREPLY=()
        local cur

        cur=${COMP_WORDS[COMP_CWORD]}

        if [[ "$cur" == -* ]]; then
                # return list of available options
                COMPREPLY=( $( compgen -W '-a -c -f --curl --wget' | grep ^$cur ) )
        else
                # return list of available medias
                _urpmi.medias
        fi

}
[ "$have" ] && complete -F _urpmi.update urpmi.update
have urpmi.addmedia &&
_urpmi.addmedia()
{
        COMPREPLY=()
        local cur i args

        cur=${COMP_WORDS[COMP_CWORD]}

        if [[ "$cur" == -* ]]; then
                # return list of available options
                COMPREPLY=( $( compgen -W '-c -h -f --wget --curl --update --distrib' 
| 
grep ^$cur ) )
        else
                # count number of mandatory args given sofar
                args=$COMP_CWORD
                for (( i=1; i < COMP_CWORD; i++ )); do
                        if [[ "${COMP_WORDS[i]}" == -* ]]; then
                                args=$(($args-1))
                        fi
                done
                case $args in
                        1)
                                # return list of available medias
                                _urpmi.medias
                                ;;
                        2)
                                # return list of available protocols
                                COMPREPLY=( $( compgen -W 'file:// http:// ftp:// 
removable://' | grep 
^$cur ) )
                                ;;
                        3)
                                # return word "with"
                                COMPREPLY=( $( compgen -W 'with' ) )
                                ;;
                esac
        fi

}
[ "$have" ] && complete -F _urpmi.addmedia urpmi.addmedia
have urpmi.removemedia &&
_urpmi.removemedia()
{
        COMPREPLY=()
        local cur

        cur=${COMP_WORDS[COMP_CWORD]}

        if [[ "$cur" == -* ]]; then
                # if word begins with a dash, return list of available options
                COMPREPLY=( $( compgen -W '-a -c' | grep ^$cur ) )
        else
                # elsewhere, return list of available medias
                _urpmi.medias
        fi

}
[ "$have" ] && complete -F _urpmi.removemedia urpmi.removemedia

-- 
Guillaume Rousse <[EMAIL PROTECTED]>
GPG key http://lis.snv.jussieu.fr/~rousse/gpgkey.html

Reply via email to