#compdef j4-dmenu-desktop

# Some of the flags accept executables. They are matced with _files -g \(\*\).
# This is a glob that matches files that are executable.

# https://github.com/markfasheh/duperemove/blob/b76d569c4b96d4afb745b7970f87fbb0193b2792/completion/zsh/_duperemove
# can serve as inspiration for further changes to ZSH completion. Duperemove is
# similar to j4-dmenu-desktop (it doesn't have subcommands) and its ZSH
# completion script is similar to this one.

_desktop_file_quirks_values()
{
    declare -a compatibility
    compatibility=(
        'wine[compatibility with desktop files generated by Wine]'
        'multispace[accept multiple spaces as argument separators in Exec]'
    )
    _values -s , "compatibility mode" $compatibility
}

declare -a args
args=(
    '(- *)'{-h,--help}'[print help message]' #- and * mean that no flags shall follow --help
    '(- *)--version[display program version]'
    '(-b --display-binary)'{-b,--display-binary}'[display binary name after each entry]'
    '(-f --display-binary-base)'{-f,--display-binary-base}'[display basename of binary name after each entry]'
    '(-d --dmenu)'{-d,--dmenu}'=[command used to invoke dmenu]:command:_files -g \*\(\*\)'
    '--no-exec[do not execute selected command, send to stdout instead]'
    '--no-generic[do not include the generic name of desktop entries]'
    '(-t --term)'{-t,--term}'=[sets the terminal emulator used to start terminal apps]:command:_files -g \*\(\*\)'
    '--term-mode=[set terminal emulator execution strategy]:term_mode:(default xterm alacritty kitty terminator gnome-terminal custom)'
    '--usage-log=[set usage log]:file:_files'
    '--prune-bad-usage-log-entries[remove bad history entries]'
    '(-x --use-xdg-de)'{-x,--use-xdg-de}'[enables reading $XDG_CURRENT_DESKTOP to determine the desktop environment]'
    '--wait-on=[enable daemon mode]:path:_files'
    '--wrapper=[a wrapper binary]:command:_files -g \*\(\*\)'
    '(-I --i3-ipc)'{-I,--i3-ipc}'[execute desktop entries through i3 IPC]'
    '--skip-i3-exec-check[disable the check for '\''--wrapper "i3 exec"'\'']'
    '(-i --case-insensitive)'{-i,--case-insensitive}'[sort applications case insensitively]'
    '-v[be more verbose, can be specified multiple times]'
    '--log-level=[set loglevel]:level:(ERROR WARNING INFO DEBUG)'
    '--log-file=[specify a log file]:file:_files'
    '--log-file-level=[set file loglevel]:level:(ERROR WARNING INFO DEBUG)'
    '(--strict-parsing)--desktop-file-quirks=[set compatibility modes]:flags:_desktop_file_quirks_values'
    '(--desktop-file-quirks)--strict-parsing[enable strict desktop file parsing]'
)

_arguments -s $args
