# elbencho-chart bash completion

# echo shortopts (incl. single dash) and longopts (incl. double dash).
_elbencho-chart_opts()
{
   local shortopts longopts

   shortopts="
        -c
        -o
        -x
        -y
        -Y
        "

   longopts="
        --bars
        --chartsize
        --fontsize
        --imgbg
        --imgfile
        --keypos
        --linewidth
        --title
        --xrot
        --xtitle
        --ytitle
        --Ytitle
        "

    echo "$shortopts $longopts"
}

_elbencho-chart()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    
    opts="$(_elbencho-chart_opts)"
 
    case "${prev}" in
        # short options that take a string argument
        -x)
        ;&
        -y)
        ;&
        -Y)
        ;&
        # long options that take a string argument
        --chartsize)
        ;&
        --fontsize)
        ;&
        --imgbg)
        ;&
        --keypos)
        ;&
        --linewidth)
        ;&
        --title)
        ;&
        --xrot)
        ;&
        --xtitle)
        ;&
        --ytitle)
        ;&
        --Ytitle)
            return 0
        ;;

        # options that take a file/dir argument
        --imgfile)
            compopt -o filenames 2>/dev/null
            COMPREPLY=( $(compgen -f ${cur}) )
            return 0
        ;;

        # all others
        *)
        ;;
    esac

    if [[ "${cur}" = -* ]]; then
        compopt -o filenames 2>/dev/null
        COMPREPLY=( $(compgen -f -W "${opts}" -- ${cur}) )
    else
        compopt -o filenames 2>/dev/null
        COMPREPLY=( $(compgen -f -W "" -- ${cur}) )
    fi
}

complete -F _elbencho-chart elbencho-chart
