#compdef watchexec

setopt localoptions extended_glob

local cmd
local -a args
local -a _comp_priv_prefix

cmd="$words[1]"

args=(
	'(-c --clear)'{-c,--clear}'[Clear screen before executing command]'
	'(-h --help)'{-h,--help}'[Prints help information]'
	'--shell=[Change the wrapping shell, or set to none to disable]'
	'-n[Shorthand for --shell=none]'
	'--no-environment[Do not set WATCHEXEC_*_PATH environment variables for command]'
	'--no-meta[Ignore metadata changes]'
	'(-p --postpone)'{-p,--postpone}'[Wait until first change to execute command]'
	'(-r --restart)'{-r,--restart}'[Restart the process if it''s still running]'
	'(-W --watch-when-idle)'{-W,--watch-when-idle}'[Ignore events while the command is still running]'
	'(-V --version)'{-V,--version}'[Prints version information]'
	'(-v --verbose)'{-v,-vv,-vvv,-vvvv,--verbose}'[Print debugging messages to stderr]'
	'(-N --notify)'{-N,--notify}'[Send desktop notifications on command start and end]'
	'--print-events[Print triggering events to stderr (changed paths, etc)]'
	'(-d --debounce)'{-d+,--debounce=}'[Set the timeout between detected change and command execution, defaults to 100ms]:milliseconds'
	'(-e --exts)'{-e+,--exts=}'[Comma-separated list of file extensions to watch (js,css,html)]:extensions'
	'(-f --filter)'{-f+,--filter=}'[Ignore all modifications except those matching the pattern]:pattern'
	'(-i --ignore)'{-i+,--ignore=}'[Ignore modifications to paths matching the pattern]:pattern'
	'(-w --watch)'{-w+,--watch=}'[Watch a specific directory]:path:_path_files -/'
	'(-s --signal)'{-s+,--signal=}'[Send signal to process upon changes, e.g. SIGHUP]:signal'
	'--force-poll=[Forces polling mode]:interval'
	'--no-project-ignore[Skip auto-loading of project-local ignore files (.gitignore, .ignore, etc.) for filtering]'
	'--no-default-ignore[Skip auto-ignoring of commonly ignored globs]'
	'--no-global-ignore[Skip auto-loading of global or environment-wide ignore files]'
	'--no-vcs-ignore[Skip auto-loading of VCS ignore files for filtering]'
	'(-)1:command: _command_names -e'
	'*::arguments:{ _comp_priv_prefix=( $cmd -n ${(kv)opt_args[-u]} ) ; _normal }'
)

_arguments -s -S $args
