# (C) 2010-2025 magicant

# Completion script for the "cd" built-in command.
# Completion function "completion/cd" is used for the "dirs", "pushd", "popd"
# built-ins as well.

function completion/cd {

        typeset OPTIONS ARGOPT PREFIX
        OPTIONS=( #>#
        "--help"
        ) #<#
        case ${WORDS[1]} in
        (cd|pushd)
                OPTIONS=("$OPTIONS" #>#
                "e --ensure-pwd; exit with status 1 if the new PWD cannot be determined"
                "L --logical; keep symbolic links in the \$PWD variable as is"
                "P --physical; resolve symbolic links in the \$PWD variable"
                "--default-directory:; specify the default directory to change to"
                ) #<#
                if [ "${WORDS[1]}" = "pushd" ]; then
                        OPTIONS=("$OPTIONS" #>#
                        "--remove-duplicates; remove duplicates in the directory stack"
                        ) #<#
                fi
                ;;
        (dirs)
                OPTIONS=("$OPTIONS" #>#
                "c --clear; clear the directory stack completely"
                "v --verbose; print stack entries with their indices"
                ) #<#
                ;;
        esac

        typeset dirstack=false
        command -f completion//parseoptions -es
        case $ARGOPT in
        (-)
                case $TARGETWORD in
                (-*[[:digit:]]*)
                        ;;
                (*)
                        command -f completion//completeoptions
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               