# (C) 2010 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" #>#
		"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
			;;
		esac
		dirstack=true
		;;
	(--default-directory)
		complete -T -P "$PREFIX" -S / -d
		;;
	(*)
		case ${WORDS[1]} in (cd|pushd)
			complete -T -S / -d
		esac
		dirstack=true
		;;
	esac

	if $dirstack; then
		case ${WORDS[1]} in (dirs|pushd|popd)
			complete -P "$PREFIX" --dirstack-index
		esac
	fi

}


# vim: set ft=sh ts=8 sts=8 sw=8 noet:
