# Debian apt-get(8) completion.

_apt_eole()
{
    local cur prev special i

    COMPREPLY=()
    cur=`_get_cword`
    prev=${COMP_WORDS[COMP_CWORD-1]}

    for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
        if [[ ${COMP_WORDS[i]} == @(install|remove|update|upgrade|dist-upgrade) ]]; then
            special=${COMP_WORDS[i]}
        fi
    done

    if [ -n "$special" ]; then
        case $special in
            remove)
                if [ -f /etc/debian_version ]; then
                    # Debian system
                    COMPREPLY=( $(_xfunc dpkg _comp_dpkg_installed_packages $cur ) )
                else
                    # assume RPM based
                    _rpm_installed_packages
                fi
                return 0
                ;;
            install|remove)
                COMPREPLY=( $( apt-cache --no-generate pkgnames "$cur" \
                    2> /dev/null ) )
                return 0
                ;;
        esac
    fi

    case "$prev" in
        -@(l|-log-level))
             COMPREPLY=( $( compgen -W 'debug info warning error critical' )  )
             return 0
             ;;
        -@(c|-container))
             containers='all'
             for dir in $(ls --color=none -1 /var/lib/lxc/)
	     do
		 test -d /var/lib/lxc/${dir} && containers="$containers $dir"
	     done
             COMPREPLY=( $( compgen -W "$containers" -- "$cur" )  )
             return 0
             ;;
    esac

    if [[ "$cur" == -* ]]; then
        COMPREPLY=( $( compgen -W '-d -h -l -v --help --log-level --verbose' \
	    -- "$cur" ) )
    elif [ -z "$special" ]; then
        COMPREPLY=( $( compgen -W 'update install remove upgrade list-upgrade dist-upgrade' -- "$cur" ) )
    fi

    return 0
}
complete -F _apt_eole $filenames apt-eole

