# 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

_nbfc_compgen_w_replacement() {
  local cur word append=0

  [[ "$1" == "-a" ]] && { shift; append=1; }
  [[ "$1" == "--" ]] && { shift; }

  cur="$1"
  shift

  (( append )) || COMPREPLY=()

  for word; do
    if [[ "$word" == "$cur"* ]]; then
      COMPREPLY+=("$(printf '%q' "$word")")
    fi
  done
}

_nbfc_parse_commandline() {
  POSITIONALS=()
  END_OF_OPTIONS=0
  POSITIONAL_NUM=0

  local cmd="${words[0]}" argi arg i char trailing_chars

  for ((argi=1; argi < ${#words[@]} - 1; ++argi)); do
    arg="${words[argi]}"

    case "$arg" in
      --)
        END_OF_OPTIONS=1
        for ((++argi; argi < ${#words[@]}; ++argi)); do
          POSITIONALS[POSITIONAL_NUM++]="${words[argi]}"
        done
        break;;
      -)
        POSITIONALS[POSITIONAL_NUM++]="-";;
      -*)
        case "$cmd" in 'nbfc set')
          case "$arg" in
            --auto)
              OPT_auto+=(_OPT_ISSET_)
              continue;;
            --speed)
              OPT_speed+=("${words[++argi]}")
              continue;;
            --speed=*)
              OPT_speed+=("${arg#*=}")
              continue;;
            --fan)
              OPT_fan+=("${words[++argi]}")
              continue;;
            --fan=*)
              OPT_fan+=("${arg#*=}")
              continue;;
          esac
        esac

        case "$cmd" in 'nbfc config')
          case "$arg" in
            --list)
              OPT_list+=(_OPT_ISSET_)
              continue;;
            --set)
              OPT_set+=("${words[++argi]}")
              continue;;
            --set=*)
              OPT_set+=("${arg#*=}")
              continue;;
            --apply)
              OPT_apply+=("${words[++argi]}")
              continue;;
            --apply=*)
              OPT_apply+=("${arg#*=}")
              continue;;
            --recommend)
              OPT_recommend+=(_OPT_ISSET_)
              continue;;
          esac
        esac

        case "$cmd" in 'nbfc status')
          case "$arg" in
            --all)
              OPT_all+=(_OPT_ISSET_)
              continue;;
            --service)
              OPT_service+=(_OPT_ISSET_)
              continue;;
            --fan)
              OPT_fan+=("${words[++argi]}")
              continue;;
            --fan=*)
              OPT_fan+=("${arg#*=}")
              continue;;
            --watch)
              OPT_watch+=("${words[++argi]}")
              continue;;
            --watch=*)
              OPT_watch+=("${arg#*=}")
              continue;;
          esac
        esac

        case "$cmd" in 'nbfc restart')
          case "$arg" in
            --read-only)
              OPT_read_only+=(_OPT_ISSET_)
              continue;;
          esac
        esac

        case "$cmd" in 'nbfc start')
          case "$arg" in
            --read-only)
              OPT_read_only+=(_OPT_ISSET_)
              continue;;
          esac
        esac

        case "$cmd" in nbfc)
          case "$arg" in
            --help)
              OPT_help+=(_OPT_ISSET_)
              continue;;
            --version)
              OPT_version+=(_OPT_ISSET_)
              continue;;
          esac
        esac
        for ((i=1; i < ${#arg}; ++i)); do
          char="${arg:$i:1}"
          trailing_chars="${arg:$((i + 1))}"
          case "$cmd" in 'nbfc set')
            case "$char" in
              a)
                OPT_auto+=(_OPT_ISSET_);;
              s)
                if [[ -n "$trailing_chars" ]]
                then OPT_speed+=("$trailing_chars")
                else OPT_speed+=("${words[++argi]}")
                fi
                continue 2;;
              f)
                if [[ -n "$trailing_chars" ]]
                then OPT_fan+=("$trailing_chars")
                else OPT_fan+=("${words[++argi]}")
                fi
                continue 2;;
            esac
          esac

          case "$cmd" in 'nbfc config')
            case "$char" in
              l)
                OPT_list+=(_OPT_ISSET_);;
              s)
                if [[ -n "$trailing_chars" ]]
                then OPT_set+=("$trailing_chars")
                else OPT_set+=("${words[++argi]}")
                fi
                continue 2;;
              a)
                if [[ -n "$trailing_chars" ]]
                then OPT_apply+=("$trailing_chars")
                else OPT_apply+=("${words[++argi]}")
                fi
                continue 2;;
              r)
                OPT_recommend+=(_OPT_ISSET_);;
            esac
          esac

          case "$cmd" in 'nbfc status')
            case "$char" in
              a)
                OPT_all+=(_OPT_ISSET_);;
              s)
                OPT_service+=(_OPT_ISSET_);;
              f)
                if [[ -n "$trailing_chars" ]]
                then OPT_fan+=("$trailing_chars")
                else OPT_fan+=("${words[++argi]}")
                fi
                continue 2;;
              w)
                if [[ -n "$trailing_chars" ]]
                then OPT_watch+=("$trailing_chars")
                else OPT_watch+=("${words[++argi]}")
                fi
                continue 2;;
            esac
          esac

          case "$cmd" in 'nbfc restart')
            case "$char" in
              r)
                OPT_read_only+=(_OPT_ISSET_);;
            esac
          esac

          case "$cmd" in 'nbfc start')
            case "$char" in
              r)
                OPT_read_only+=(_OPT_ISSET_);;
            esac
          esac

          case "$cmd" in nbfc)
            case "$char" in
              h)
                OPT_help+=(_OPT_ISSET_);;
            esac
          esac
        done;;
      *)
        POSITIONALS[POSITIONAL_NUM++]="$arg"
        if (( POSITIONAL_NUM == 1 )); then
          case "$arg" in
            start)
              cmd+=" start";;
            stop)
              cmd+=" stop";;
            restart)
              cmd+=" restart";;
            status)
              cmd+=" status";;
            config)
              cmd+=" config";;
            set)
              cmd+=" set";;
            wait-for-hwmon)
              cmd+=" wait-for-hwmon";;
            help)
              cmd+=" help";;
            *) cmd+=" $arg";;
          esac
        fi
        ;;
    esac
  done

  for ((; argi < ${#words[@]}; ++argi)); do
    arg="${words[$argi]}"

    case "$arg" in
      -) POSITIONALS[POSITIONAL_NUM++]="$arg";;
      -*);;
      *) POSITIONALS[POSITIONAL_NUM++]="$arg";;
    esac
  done
}

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

_nbfc_exec() {
  local item desc

  while IFS=$'\t' read -r item desc; do
    if [[ "$item" == "$cur"* ]]; then
      COMPREPLY+=("$(printf '%q' "$item")")
    fi
  done < <(eval "$1")
}

_nbfc() {
  local cur prev words cword split
  _init_completion -n = || return

  local END_OF_OPTIONS POSITIONALS POSITIONAL_NUM
  local -a OPT_help OPT_version

  _nbfc_parse_commandline

  if (( 0 < POSITIONAL_NUM )); then
    case "${POSITIONALS[0]}" in
      start) _nbfc_start && return 0 || return 1;;
      stop) _nbfc_stop && return 0 || return 1;;
      restart) _nbfc_restart && return 0 || return 1;;
      status) _nbfc_status && return 0 || return 1;;
      config) _nbfc_config && return 0 || return 1;;
      set) _nbfc_set && return 0 || return 1;;
      wait-for-hwmon) _nbfc_wait_for_hwmon && return 0 || return 1;;
      help) _nbfc_help && return 0 || return 1;;
    esac
  fi

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts=()
    (( ! ${#OPT_help} )) && opts+=(-h --help)
    (( ! ${#OPT_version} )) && opts+=(--version)
    _nbfc_compgen_w_replacement -a -- "$cur" "${opts[@]}"
    return 1
  fi

  test "$POSITIONAL_NUM" -eq 1 && {
    _nbfc_compgen_w_replacement -- "$cur" start stop restart status config set wait-for-hwmon help
    return 0;
  }

  return 1
}

_nbfc_start() {
  local END_OF_OPTIONS POSITIONALS POSITIONAL_NUM
  local -a OPT_read_only OPT_help OPT_version

  _nbfc_parse_commandline

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts=()
    (( ! ${#OPT_read_only} )) && opts+=(-r --read-only)
    _nbfc_compgen_w_replacement -a -- "$cur" "${opts[@]}"
    return 1
  fi

  return 1
}

_nbfc_stop() {
  return 0
}

_nbfc_restart() {
  local END_OF_OPTIONS POSITIONALS POSITIONAL_NUM
  local -a OPT_read_only OPT_help OPT_version

  _nbfc_parse_commandline

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts=()
    (( ! ${#OPT_read_only} )) && opts+=(-r --read-only)
    _nbfc_compgen_w_replacement -a -- "$cur" "${opts[@]}"
    return 1
  fi

  return 1
}

_nbfc_status() {
  local END_OF_OPTIONS POSITIONALS POSITIONAL_NUM
  local -a OPT_all OPT_service OPT_fan OPT_watch OPT_help OPT_version

  _nbfc_parse_commandline

  __complete_option() {
    local opt="$1" cur="$2" mode="$3"

    case "$opt" in
      --fan|-f|--watch|-w)
        return 0;;
    esac

    return 1
  }

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

  case "$cur" in
    --*=*)
      __complete_option "${cur%%=*}" "${cur#*=}" WITH_OPTIONALS && return 0;;
    -*=*);;
    --*);;
    -*)
        local i
        for ((i=2; i <= ${#cur}; ++i)); do
          local pre="${cur:0:$i}" value="${cur:$i}"
          __complete_option "-${pre: -1}" "$value" WITH_OPTIONALS && {
            _nbfc_prefix_compreply "$pre"
            return 0
          }
        done;;
  esac

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts=()
    (( ! ${#OPT_all} && ! ${#OPT_service} && ! ${#OPT_fan} )) && opts+=(-a --all)
    (( ! ${#OPT_service} && ! ${#OPT_all} && ! ${#OPT_fan} )) && opts+=(-s --service)
    (( ! ${#OPT_fan} && ! ${#OPT_all} && ! ${#OPT_service} )) && opts+=(-f --fan)
    (( ! ${#OPT_watch} )) && opts+=(-w --watch)
    _nbfc_compgen_w_replacement -a -- "$cur" "${opts[@]}"
    return 1
  fi

  return 1
}

_nbfc_config() {
  local END_OF_OPTIONS POSITIONALS POSITIONAL_NUM
  local -a OPT_list OPT_set OPT_apply OPT_recommend OPT_help OPT_version

  _nbfc_parse_commandline

  __complete_option() {
    local opt="$1" cur="$2" mode="$3"

    case "$opt" in
      --set|-s|--apply|-a)
        pushd /usr/share/nbfc/configs &>/dev/null && {
          _filedir
          popd &>/dev/null
        }
        return 0;;
    esac

    return 1
  }

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

  case "$cur" in
    --*=*)
      __complete_option "${cur%%=*}" "${cur#*=}" WITH_OPTIONALS && return 0;;
    -*=*);;
    --*);;
    -*)
        local i
        for ((i=2; i <= ${#cur}; ++i)); do
          local pre="${cur:0:$i}" value="${cur:$i}"
          __complete_option "-${pre: -1}" "$value" WITH_OPTIONALS && {
            _nbfc_prefix_compreply "$pre"
            return 0
          }
        done;;
  esac

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts=()
    (( ! ${#OPT_list} && ! ${#OPT_set} && ! ${#OPT_apply} && ! ${#OPT_recommend} )) && opts+=(-l --list)
    (( ! ${#OPT_set} && ! ${#OPT_list} && ! ${#OPT_apply} && ! ${#OPT_recommend} )) && opts+=(-s --set)
    (( ! ${#OPT_apply} && ! ${#OPT_list} && ! ${#OPT_set} && ! ${#OPT_recommend} )) && opts+=(-a --apply)
    (( ! ${#OPT_recommend} && ! ${#OPT_list} && ! ${#OPT_set} && ! ${#OPT_apply} )) && opts+=(-r --recommend)
    _nbfc_compgen_w_replacement -a -- "$cur" "${opts[@]}"
    return 1
  fi

  return 1
}

_nbfc_set() {
  local END_OF_OPTIONS POSITIONALS POSITIONAL_NUM
  local -a OPT_auto OPT_speed OPT_fan OPT_help OPT_version

  _nbfc_parse_commandline

  __complete_option() {
    local opt="$1" cur="$2" mode="$3"

    case "$opt" in
      --speed|-s)
        return 0;;
      --fan|-f)
        _nbfc_exec 'nbfc complete-fans'
        return 0;;
    esac

    return 1
  }

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

  case "$cur" in
    --*=*)
      __complete_option "${cur%%=*}" "${cur#*=}" WITH_OPTIONALS && return 0;;
    -*=*);;
    --*);;
    -*)
        local i
        for ((i=2; i <= ${#cur}; ++i)); do
          local pre="${cur:0:$i}" value="${cur:$i}"
          __complete_option "-${pre: -1}" "$value" WITH_OPTIONALS && {
            _nbfc_prefix_compreply "$pre"
            return 0
          }
        done;;
  esac

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts=()
    (( ! ${#OPT_auto} && ! ${#OPT_speed} )) && opts+=(-a --auto)
    (( ! ${#OPT_speed} && ! ${#OPT_auto} )) && opts+=(-s --speed)
    (( ! ${#OPT_fan} )) && opts+=(-f --fan)
    _nbfc_compgen_w_replacement -a -- "$cur" "${opts[@]}"
    return 1
  fi

  return 1
}

_nbfc_wait_for_hwmon() {
  return 0
}

_nbfc_help() {
  return 0
}

complete -F _nbfc nbfc

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