#!/bin/bash

CDS_COMMAND="cds"

_completeCds()
{
    local current options previous
    COMPREPLY=()
    current="${COMP_WORDS[COMP_CWORD]}"
    previous="${COMP_WORDS[COMP_CWORD - 1]}"

    # double quoting needed to avoid word 'h' to be recognized as command shortcut 'help'
    options=$($CDS_COMMAND completion --shell bash --prev "'$previous'" --curr "'$current'" --line "'${COMP_WORDS[*]}'")

    COMPREPLY=( $(compgen -W "${options}" -- ${current}) )
    compopt -o nosort -o nospace
    return 0
}

complete -F _completeCds $CDS_COMMAND