_se(){
	COMPREPLY=()
	local cur="${COMP_WORDS[COMP_CWORD]}"
	local prev="${COMP_WORDS[COMP_CWORD-1]}"
	local commands="--help --plain --version british2american build build-images build-manifest build-spine build-title build-toc clean compare-versions create-draft dec2roman extract-ebook find-mismatched-dashes find-mismatched-diacritics find-unusual-characters help hyphenate interactive-replace lint make-url-safe modernize-spelling prepare-release recompose-epub renumber-endnotes roman2dec semanticate shift-endnotes split-file titlecase typogrify unicode-names version word-count xpath"
	if [[ $COMP_CWORD -gt 1 ]]; then
		case "${COMP_WORDS[1]}" in
			british2american)
				COMPREPLY+=($(compgen -W "-f --force -h --help -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			build)
				# Complete directory names after -o= --output-dir=
				if [[ ${prev} == "-"* && ${cur} == "=" ]] ; then
					COMPREPLY+=($(compgen -d -X ".*"))
					return 0
				fi
				COMPREPLY+=($(compgen -W "-b --kobo -c --check -h --help -k --kindle -o= --output-dir= -p --proof -v --verbose -y --check-only" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			build-images)
				COMPREPLY+=($(compgen -W "-h --help -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			build-manifest)
				COMPREPLY+=($(compgen -W "-h --help -s --stdout" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			build-spine)
				COMPREPLY+=($(compgen -W "-h --help -s --stdout" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			build-title)
				COMPREPLY+=($(compgen -W "-h --help -n --no-newline -s --stdout" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X "!*.xhtml" -- "${cur}"))
				;;
			build-toc)
				COMPREPLY+=($(compgen -W "-h --help -s --stdout" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			clean)
				COMPREPLY+=($(compgen -W "-h --help -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.svg" -- "${cur}"))
				;;
			compare-versions)
				COMPREPLY+=($(compgen -W "-h --help -i --include-se-files -n --no-images -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			create-draft)
				COMPREPLY+=($(compgen -W "-a --author -e --email -h --help -i --illustrator -o --offline -p --pg-id -r --translator -t --title -w --white-label" -- "${cur}"))
				;;
			dec2roman)
				COMPREPLY+=($(compgen -W "-h --help -n --no-newline" -- "${cur}"))
				;;
			extract-ebook)
				# Complete directory names after -o= --output-dir=
				if [[ ${prev} == "-"* && ${cur} == "=" ]] ; then
					COMPREPLY+=($(compgen -d -X ".*"))
					return 0
				fi
				COMPREPLY+=($(compgen -W "-h --help -o= --output-dir= -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.mobi" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.azw3" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.epub" -- "${cur}"))
				;;
			find-mismatched-dashes)
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			find-mismatched-diacritics)
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			find-unusual-characters)
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			help)
				;;
			hyphenate)
				COMPREPLY+=($(compgen -W "-h --help -i --ignore-h-tags -l --language -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			interactive-replace)
				COMPREPLY+=($(compgen -W "-h --help -i --ignore-case -m --multiline -d --dotall -v --vim" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			lint)
				COMPREPLY+=($(compgen -W "-h --help -a= --allow= -s --skip-lint-ignore -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			make-url-safe)
				COMPREPLY+=($(compgen -W "-h --help -n --no-newline" -- "${cur}"))
				;;
			modernize-spelling)
				COMPREPLY+=($(compgen -W "-h --help -n --no-hyphens -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			prepare-release)
				COMPREPLY+=($(compgen -W "-h --help -r --no-revision -w --no-word-count -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			recompose-epub)
				# Complete directory names after -o= --output=
				if [[ ${prev} == "-"* && ${cur} == "=" ]] ; then
					COMPREPLY+=($(compgen -f -X ".*"))
					return 0
				fi
				COMPREPLY+=($(compgen -W "-h --help -o= --output= -x --xhtml -e --extra-css-file" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			renumber-endnotes)
				COMPREPLY+=($(compgen -W "-h --help -b --brute-force -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				;;
			roman2dec)
				COMPREPLY+=($(compgen -W "-h --help -n --no-newline" -- "${cur}"))
				;;
			semanticate)
				COMPREPLY+=($(compgen -W "-h --help -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			split-file)
				COMPREPLY+=($(compgen -W "-f --filename-format= -h --help -s --start-at= -t --template-file=" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.htm" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.html" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			titlecase)
				COMPREPLY+=($(compgen -W "-h --help -n --no-newline" -- "${cur}"))
				;;
			typogrify)
				COMPREPLY+=($(compgen -W "-h --help -n --no-quotes -v --verbose" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			unicode-names)
				;;
			version)
				;;
			word-count)
				COMPREPLY+=($(compgen -W "-c --categorize -h --help -p --ignore-pg-boilerplate -x --exclude-se-files" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.htm" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.html" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
			xpath)
				COMPREPLY+=($(compgen -W "-h --help -f --only-filenames" -- "${cur}"))
				COMPREPLY+=($(compgen -d -X ".*" -- "${cur}"))
				COMPREPLY+=($(compgen -f -X "!*.xhtml" -- "${cur}"))
				;;
		esac
	else
		COMPREPLY+=($(compgen -W "${commands}" -- "${cur}"))
	fi
}

complete -F _se se
