# This script was generated by crazy-complete.
# crazy-complete: A tool that creates robust and reliable autocompletion scripts for Bash, Fish and Zsh.
# For more information, visit: https://github.com/crazy-complete/crazy-complete

_j4-dmenu-desktop__value_list() {
  local separator="$1"; shift

  compopt -o nospace

  local cur_unquoted break_pos in_quotes
  _j4-dmenu-desktop__dequote "$cur" cur_unquoted break_pos in_quotes

  if [[ -z "$cur_unquoted" ]]; then
    COMPREPLY=("$@")
    return
  fi

  local value having_value having_values=() remaining_values=()

  IFS="$separator" read -r -a having_values <<< "$cur_unquoted"

  for value; do
    if ! _j4-dmenu-desktop__array_contains "$value" "${having_values[@]}"; then
      remaining_values+=("$value")
    fi
  done

  COMPREPLY=()

  local cur_stripped="$cur_unquoted"
  if (( break_pos > -1 )); then
    cur_stripped="${cur_stripped:break_pos}"
  fi

  if [[ "${cur_unquoted: -1}" == "$separator" ]]; then
    for value in "${remaining_values[@]}"; do
      COMPREPLY+=("$cur_stripped$value")
    done
  elif (( ${#remaining_values[@]} )); then
    if _j4-dmenu-desktop__array_contains "${having_values[-1]}" "$@"; then
      COMPREPLY+=("$cur_stripped$separator")
    elif (( ${#having_values[@]} )); then
      local cur_last_value=${having_values[-1]}
      cur_stripped="${cur_stripped%"$cur_last_value"}"

      for value in "${remaining_values[@]}"; do
        if [[ "$value" == "$cur_last_value"* ]]; then
          COMPREPLY+=("$cur_stripped$value")
        fi
      done
    fi
  fi
}

_j4-dmenu-desktop__dequote() {
  local in="$1" len=${#1} i=0 result='' ___break_pos=-1 ___in_quotes=0

  for ((; i < len; ++i)); do
    case "${in:i:1}" in
      "'")
        ___in_quotes=1
        for ((++i; i < len; ++i)); do
          [[ "${in:i:1}" == "'" ]] && { ___in_quotes=0; break; }
          result+="${in:i:1}"
        done;;
      '"')
        ___in_quotes=1
        for ((++i; i < len; ++i)); do
          [[ "${in:i:1}" == '"' ]] && { ___in_quotes=0; break; }

          if [[ "${in:i:1}" == '\' ]]; then
            result+="${in:$((++i)):1}"
          else
            result+="${in:i:1}"
          fi
        done;;
      '\')
        result+="${in:$((++i)):1}";;
      [$COMP_WORDBREAKS])
        result+="${in:i:1}"
        ___break_pos=${#result};;
      *)
        result+="${in:i:1}";;
    esac
  done

  local -n ___RESULT=$2
  local -n ___BREAK_POS=$3
  local -n ___IN_QUOTES=$4
  ___RESULT="$result"
  ___BREAK_POS=$___break_pos
  ___IN_QUOTES=$___in_quotes
}

_j4-dmenu-desktop__array_contains() {
  local w='' search="$1"; shift;
  for w; do [[ "$search" == "$w" ]] && return 0; done
  return 1
}

_j4-dmenu-desktop__prefix_compreply() {
  [[ "$cur" == *[$COMP_WORDBREAKS]* ]] && return

  local i prefix="$1"
  for ((i=0; i < ${#COMPREPLY[@]}; ++i)); do
    COMPREPLY[i]="$prefix${COMPREPLY[i]}"
  done
}

_j4-dmenu-desktop__dequote_words() {
  local word dequoted break_pos in_quotes

  words_dequoted=()

  for word in "${words[@]}"; do
    _j4-dmenu-desktop__dequote "$word" dequoted break_pos in_quotes
    words_dequoted+=("$dequoted")
  done
}

_j4-dmenu-desktop__parse_commandline() {
  END_OF_OPTIONS=0

  local cmd="root" argi arg i char trailing_chars VAR ARGS

  __find_option() {
    case "$2" in
      -h|--help) VAR=OPT_help; ARGS=0; return;;
      --version) VAR=OPT_version; ARGS=0; return;;
      -b|--display-binary) VAR=OPT_display_binary; ARGS=0; return;;
      -f|--display-binary-base) VAR=OPT_display_binary_base; ARGS=0; return;;
      -d|--dmenu) VAR=OPT_dmenu; ARGS=1; return;;
      --no-exec) VAR=OPT_no_exec; ARGS=0; return;;
      --no-generic) VAR=OPT_no_generic; ARGS=0; return;;
      -t|--term) VAR=OPT_term; ARGS=1; return;;
      --term-mode) VAR=OPT_term_mode; ARGS=1; return;;
      --usage-log) VAR=OPT_usage_log; ARGS=1; return;;
      --prune-bad-usage-log-entries) VAR=OPT_prune_bad_usage_log_entries; ARGS=0; return;;
      -x|--use-xdg-de) VAR=OPT_use_xdg_de; ARGS=0; return;;
      --wait-on) VAR=OPT_wait_on; ARGS=1; return;;
      --wrapper) VAR=OPT_wrapper; ARGS=1; return;;
      -I|--i3-ipc) VAR=OPT_i3_ipc; ARGS=0; return;;
      --skip-i3-exec-check) VAR=OPT_skip_i3_exec_check; ARGS=0; return;;
      -i|--case-insensitive) VAR=OPT_case_insensitive; ARGS=0; return;;
      -v) VAR=OPT_v; ARGS=0; return;;
      --log-level) VAR=OPT_log_level; ARGS=1; return;;
      --log-file) VAR=OPT_log_file; ARGS=1; return;;
      --log-file-level) VAR=OPT_log_file_level; ARGS=1; return;;
      --desktop-file-quirks) VAR=OPT_desktop_file_quirks; ARGS=1; return;;
      --strict-parsing) VAR=OPT_strict_parsing; ARGS=0; return;;
    esac
    return 1
  }

  __append_to_array() {
    local -n arr=$1
    arr+=("$2")
  }

  for ((argi=1; argi < cword; ++argi)); do
    arg="${words_dequoted[argi]}"

    case "$arg" in
      --)
        END_OF_OPTIONS=1
        return;;
      --*=*)
        if __find_option "$cmd" "${arg%%=*}"
        then __append_to_array "$VAR" "${arg#*=}"
        fi;;
      --*)
        if __find_option "$cmd" "$arg"; then
          if [[ "$ARGS" == 1 ]]
          then __append_to_array "$VAR" "${words_dequoted[++argi]}"
          else __append_to_array "$VAR" "_OPT_ISSET_"
          fi
        fi;;
      -?*) # ignore '-'

        for ((i=1; i < ${#arg}; ++i)); do
          char="${arg:$i:1}"
          trailing_chars="${arg:$((i + 1))}"

          if __find_option "$cmd" "-$char"; then
            if [[ "$ARGS" == 1 ]]; then
              if [[ -n "$trailing_chars" ]]
              then __append_to_array "$VAR" "$trailing_chars"
              else __append_to_array "$VAR" "${words_dequoted[++argi]}"
              fi
              break;
            else
              __append_to_array "$VAR" "_OPT_ISSET_"
            fi
          fi
        done
        ;;
    esac
  done
}

_j4_dmenu_desktop() {
  local cur prev words cword split words_dequoted
  _init_completion -n =: || return
  _j4-dmenu-desktop__dequote_words

  local END_OF_OPTIONS POSITIONALS
  local -a OPT_help OPT_version OPT_display_binary OPT_display_binary_base
  local -a OPT_dmenu OPT_no_exec OPT_no_generic OPT_term OPT_term_mode
  local -a OPT_usage_log OPT_prune_bad_usage_log_entries OPT_use_xdg_de
  local -a OPT_wait_on OPT_wrapper OPT_i3_ipc OPT_skip_i3_exec_check
  local -a OPT_case_insensitive OPT_v OPT_log_level OPT_log_file
  local -a OPT_log_file_level OPT_desktop_file_quirks OPT_strict_parsing
  _j4-dmenu-desktop__parse_commandline

  __complete_option() {
    local opt="$1" cur="$2" ret=0

    case "$opt" in
      -@(-@(dmenu|term|wrapper)|d|t))
        COMPREPLY=($(compgen -A command -- "$cur"));;
      --term-mode)
        COMPREPLY=($(compgen -W 'default xterm alacritty kitty terminator gnome-terminal custom' -- "$cur"));;
      --@(log-file|usage-log|wait-on))
        _filedir;;
      --log-@(file-level|level))
        COMPREPLY=($(compgen -W 'ERROR WARNING INFO DEBUG' -- "$cur"));;
      --desktop-file-quirks)
        _j4-dmenu-desktop__value_list , wine multispace nowine nomultispace;;
      *) ret=1;;
    esac

    return $ret
  }

  case "$prev" in
    --*) __complete_option "$prev" "$cur" && return 0;;
    -*([hbfxIiv])[dt])
         __complete_option "-${prev: -1}" "$cur" && return 0;;
  esac

  case "$cur" in
    --*=*)
      __complete_option "${cur%%=*}" "${cur#*=}" && return 0;;
    --*);;
    -*([hbfxIiv])[dt]*)
      local i
      for ((i=2; i <= ${#cur}; ++i)); do
        local pre="${cur:0:$i}" value="${cur:$i}"
        __complete_option "-${pre: -1}" "$value" && {
          _j4-dmenu-desktop__prefix_compreply "$pre"
          return 0
        }
      done;;
  esac

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    if (( ! ${#OPT_help[@]} && ! ${#OPT_version[@]} )); then
      opts+=(-h --help --version -v)
      (( ! ${#OPT_display_binary[@]} )) && opts+=(-b --display-binary)
      (( ! ${#OPT_display_binary_base[@]} )) && opts+=(-f --display-binary-base)
      (( ! ${#OPT_dmenu[@]} )) && opts+=(-d --dmenu=)
      (( ! ${#OPT_no_exec[@]} )) && opts+=(--no-exec)
      (( ! ${#OPT_no_generic[@]} )) && opts+=(--no-generic)
      (( ! ${#OPT_term[@]} )) && opts+=(-t --term=)
      (( ! ${#OPT_term_mode[@]} )) && opts+=(--term-mode=)
      (( ! ${#OPT_usage_log[@]} )) && opts+=(--usage-log=)
      (( ! ${#OPT_prune_bad_usage_log_entries[@]} )) && opts+=(--prune-bad-usage-log-entries)
      (( ! ${#OPT_use_xdg_de[@]} )) && opts+=(-x --use-xdg-de)
      (( ! ${#OPT_wait_on[@]} )) && opts+=(--wait-on=)
      (( ! ${#OPT_wrapper[@]} )) && opts+=(--wrapper=)
      (( ! ${#OPT_i3_ipc[@]} )) && opts+=(-I --i3-ipc)
      (( ! ${#OPT_skip_i3_exec_check[@]} )) && opts+=(--skip-i3-exec-check)
      (( ! ${#OPT_case_insensitive[@]} )) && opts+=(-i --case-insensitive)
      (( ! ${#OPT_log_level[@]} )) && opts+=(--log-level=)
      (( ! ${#OPT_log_file[@]} )) && opts+=(--log-file=)
      (( ! ${#OPT_log_file_level[@]} )) && opts+=(--log-file-level=)
      (( ! ${#OPT_desktop_file_quirks[@]} && ! ${#OPT_strict_parsing[@]} )) && opts+=(--desktop-file-quirks= --strict-parsing)
    fi
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  return 1
}

complete -F _j4_dmenu_desktop j4-dmenu-desktop

# vim: ft=sh ts=2 sts=2 sw=2 et