#compdef fd

autoload -U is-at-least

_fd() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'*--and=[Additional search patterns that need to be matched]:pattern:_default' \
'-d+[Set maximum search depth (default\: none)]:depth:_default' \
'--max-depth=[Set maximum search depth (default\: none)]:depth:_default' \
'--min-depth=[Only show search results starting at the given depth.]:depth:_default' \
'(-d --max-depth --min-depth)--exact-depth=[Only show search results at the exact given depth]:depth:_default' \
'*-E+[Exclude entries that match the given glob pattern]:glob:_default' \
'*--exclude=[Exclude entries that match the given glob pattern]:glob:_default' \
'*-t+[Filter by type\: file (f), directory (d/dir), symlink (l), executable (x), empty (e), socket (s), pipe (p), char-device (c), block-device (b)]:filetype:((file\:""
directory\:""
symlink\:""
block-device\:""
char-device\:""
executable\:"A file which is executable by the current effective user"
empty\:""
socket\:""
pipe\:""))' \
'*--type=[Filter by type\: file (f), directory (d/dir), symlink (l), executable (x), empty (e), socket (s), pipe (p), char-device (c), block-device (b)]:filetype:((file\:""
directory\:""
symlink\:""
block-device\:""
char-device\:""
executable\:"A file which is executable by the current effective user"
empty\:""
socket\:""
pipe\:""))' \
'*-e+[Filter by extension]:ext:_default' \
'*--extension=[Filter by extension]:ext:_default' \
'*-S+[Limit results based on the size of files]:size:_default' \
'*--size=[Limit results based on the size of files]:size:_default' \
'--changed-within=[Filter by file modification time (newer than)]:date|dur:_default' \
'--changed-before=[Filter by file modification time (older than)]:date|dur:_default' \
'-o+[Filter by owning user and/or group]:user:group:_default' \
'--owner=[Filter by owning user and/or group]:user:group:_default' \
'(-l --list-details)--format=[Print results according to template]:fmt:_default' \
'(-l --list-details)*-x+[Execute a command for each search result]:cmd:_default' \
'(-l --list-details)*--exec=[Execute a command for each search result]:cmd:_default' \
'(-x --exec -l --list-details)*-X+[Execute a command with all search results at once]:cmd:_default' \
'(-x --exec -l --list-details)*--exec-batch=[Execute a command with all search results at once]:cmd:_default' \
'--batch-size=[Max number of arguments to run as a batch size with -X]:size:_default' \
'*--ignore-file=[Add a custom ignore-file in '\''.gitignore'\'' format]:path:_files' \
'-c+[When to use colors]:when:((auto\:"show colors if the output goes to an interactive console (default)"
always\:"always use colorized output"
never\:"do not use colorized output"))' \
'--color=[When to use colors]:when:((auto\:"show colors if the output goes to an interactive console (default)"
always\:"always use colorized output"
never\:"do not use colorized output"))' \
'--hyperlink=[Add hyperlinks to output paths]::when:((auto\:"Use hyperlinks only if color is enabled"
always\:"Always use hyperlinks when printing file paths"
never\:"Never use hyperlinks"))' \
'*--ignore-contain=[Ignore directories containing the named entry]:name:_default' \
'-j+[Set number of threads to use for searching & executing (default\: number of available CPU cores, up to a maximum of 64)]:num:_default' \
'--threads=[Set number of threads to use for searching & executing (default\: number of available CPU cores, up to a maximum of 64)]:num:_default' \
'--max-buffer-time=[Milliseconds to buffer before streami                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   