#compdef distrobox
compdef _distrobox distrobox

# Shell completion script for distrobox (zsh).
#
# Mirrors urfave/cli v3.5.0's zsh autocomplete template, with the
# same one-line fix as the bash variant: when the current word is
# exactly "--", omit it from the completion request so urfave's
# checkShellCompleteFlag doesn't bail out on the bare separator.

_distrobox() {
	local -a opts
	local current
	current=${words[-1]}
	if [[ "$current" == "-"* && "$current" != "--" ]]; then
		opts=("${(@f)$(${words[@]:0:#words[@]-1} ${current} --generate-shell-completion)}")
	else
		opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-shell-completion)}")
	fi

	if [[ "${opts[1]}" != "" ]]; then
		_describe 'values' opts
	else
		_files
	fi
}

# Don't run the completion function when being source-ed or eval-ed.
# See https://github.com/urfave/cli/issues/1874 for discussion.
if [ "$funcstack[1]" = "_distrobox" ]; then
	_distrobox
fi
