# completion settings for the exec built-in
# written by magicant
# vim: set ft=sh ts=8 sts=8 sw=8 noet:

complete -C "$1" -F comp/exec

complete -C "$1" -O a -O --as -c \
	-D "specify a name to execute the command as"
complete -C "$1" -O c -O --clear \
	-D "don't export variables from the shell"
complete -C "$1" -O f -O --force \
	-D "suppress warning about stopped jobs"
complete -C "$1" -O --help

function 'comp/exec' {
	# skip options
	shift
	while [ $# -gt 1 ]; do
		case "$1" in
			--)       shift; break;;
			--a*=*)   shift;;
			--a*|-*a) shift 2;;
			-?*)      shift;;
			*)        break;;
		esac
	done

	if [ $# -le 1 ]; then
		# complete an external command name
		complete --external-command
	else
		# complete an argument to the command that is in turn an
		# argument to the exec command
		complete -G -- "$@"
	fi
}
