_get_comps() {
    local cArg="${COMP_WORDS[COMP_CWORD]}"
    local pArg="${COMP_WORDS[COMP_CWORD-1]}"
    local ppArg="${COMP_WORDS[COMP_CWORD-2]}"
    local pName="${COMP_WORDS[0]}"
    
    local configKeys="autoUpdate titleColor descriptionColor exampleColor commandColor
    choiceColor pageSource storagePath optionsType noteOverwriteMode maxAge"
    
    local languages="en ar bn bs ca cs da de es fa fi fr hi id it ja ko lo ml ne nl
    no pl pt_BR pt_PT ro ru sh sr sv ta th tr uk uz zh zh_TW"

    local opts="-C --config -c --color -d --delete -e --edit -h --help \
    -L --language -l --list -n --note -p --platform -r --render -S --source \
    -s --search -u --update -v --version -- --colors --dry --long --long-options\
    --no-auto --script --scripting --short --short-options --storage-path"

    if [[ $cArg == -* || $pArg == -h || $pArg == --help ]]; then
        mapfile -t COMPREPLY < <(compgen -W "$opts" -- "$cArg")
        return 0
    fi

    case $pArg in
        -r|--render|--storage-path)
            mapfile -t COMPREPLY < <(compgen -f -- "$cArg");;
        --color)
            mapfile -t COMPREPLY < <(compgen -W "never" -- "$cArg");;
        -L|--language)
            mapfile -t COMPREPLY < <(compgen -W "$languages" -- "$cArg");;
        -n|--note)
            mapfile -t COMPREPLY < <(compgen -W "read write edit list remove" -- "$cArg");;
        read|remove)
            [[ $ppArg == -n || $ppArg == --note ]] && \
            mapfile -t COMPREPLY < <(compgen -W "$($pName -n list --script 2> /dev/null)" -- "$cArg") || \
            mapfile -t COMPREPLY < <(compgen -W "$($pName -l --script 2> /dev/null)" -- "$cArg");;
        edit)
            if [[ $ppArg == -n || $ppArg == --note ]]; then
                mapfile -t COMPREPLY < <(compgen -W "$($pName -l --script 2> /dev/null)" -- "$cArg")
            elif [[ $ppArg == -C || $ppArg == --config ]]; then
                    return 0
            else
                mapfile -t COMPREPLY < <(compgen -W "$($pName -l --script 2> /dev/null)" -- "$cArg")
            fi
            ;;
        -C|--config)
            mapfile -t COMPREPLY < <(compgen -W "get set edit store clear" -- "$cArg");;
        get|set)
            [[ $ppArg == -C || $ppArg == --config ]] && \
            mapfile -t COMPREPLY < <(compgen -W "$configKeys" -- "$cArg") || \
            mapfile -t COMPREPLY < <(compgen -W "$($pName -l --script 2> /dev/null)" -- "$cArg");;
        *)
            mapfile -t COMPREPLY < <(compgen -W "$($pName -l --script 2> /dev/null)" -- "$cArg");;
    esac
}

complete -o bashdefault -F _get_comps cldr
