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

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

function comp/set {

typeset option=false
shift

while [ $# -gt 1 ]; do
	case "$1" in
	--)
		complete -f; return;;
	--*)
		shift;;
	[-+]*o)
		if [ $# -gt 2 ]; then
			shift 2
		else
			shift 1; option=true
		fi ;;
	[-+]?*)
		shift;;
	*)
		complete -f; return;;
	esac
done

case "$1" in
--*)
	complete -W "${1#--}"
	complete help;;
[-+]*o*)
	complete -W "${1#*o}";;
[-+]*)
	complete -W ""
	complete a \
		-D "--allexport: export all variables when assigned"
	complete b \
		-D "--notify: print job status immediately when done"
	complete e \
		-D "--errexit: exit immediately when a command's exit status is non-zero"
	complete f \
		-D "--noglob: disable pathname expansion (globbing)"
	complete h \
		-D "--hashondef: cache full paths of commands in a function when defined"
	complete m \
		-D "--monitor: enable job control"
	complete n \
		-D "--noexec: don't execute any commands"
	complete u \
		-D "--nounset: disallow expansion of undefined variables"
	complete v \
		-D "--verbose: echo commands entered to the shell"
	complete x \
		-D "--xtrace: print a command line before executing it"
	complete C \
		-D "--noclobber: disallow >-redirection to overwrite an existing file"
	complete o \
		-D "specify option by name"
	return;;
*)
	if ! $option; then
		complete -f; return
	fi ;;
esac

complete allexport \
	-D "-a: export all variables when assigned"
complete notify \
	-D "-b: print job status immediately when done"
complete notifyle \
	-D "print job status immediately when done while line-editing"
complete errexit \
	-D "-e: exit immediately when a command's exit status is non-zero"
complete noglob \
	-D "-f: disable pathname expansion (globbing)"
complete nocaseglob \
	-D "make pathname expansion case-insensitive"
complete dotglob \
	-D "don't treat a period at the beginning of a filename specially"
complete markdirs \
	-D "append a slash to directory names after pathname expansion"
complete extendedglob \
	-D "enable recursive pathname expansion"
complete nullglob \
	-D "remove words that matched nothing in pathname expansion"
complete hashondef \
	-D "-h: cache full paths of commands in a function when defined"
complete monitor \
	-D "-m: enable job control"
complete noexec \
	-D "-n: don't execute any commands"
complete nounset \
	-D "-u: disallow expansion of undefined variables"
complete verbose \
	-D "-v: echo commands entered to the shell"
complete xtrace \
	-D "-x: print a command line before executing it"
complete noclobber \
	-D "-C: disallow >-redirection to overwrite an existing file"
complete ignoreeof \
	-D "don't exit when an end-of-file is entered"
complete braceexpand \
	-D "enable brace expansion"
complete curasync \
	-D "a newly-executed background job becomes the current job"
complete curbg \
	-D "a background job becomes the current job when resumed"
complete curstop \
	-D "a background job becomes the current job when stopped"
complete histspace \
	-D "don't save a command starting with a space in the history"
complete posix \
	-D "force strict POSIX conformance"
complete vi \
	-D "vi-like line-editing"
complete emacs \
	-D "emacs-like line-editing"
complete le-convmeta \
	-D "always treat meta-key flags in line-editing"
complete le-noconvmeta \
	-D "never treat meta-key flags in line-editing"
complete le-visiblebell \
	-D "alert with a flash, not a bell"
complete le-promptsp \
	-D "ensure the prompt is printed at the beginning of a line"
complete le-alwaysrp \
	-D "always show the right prompt during line-editing"
complete le-compdebug \
	-D "print debugging info during command line completion"

}
