# 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__dequote_words() {
  local word dequoted break_pos in_quotes

  words_dequoted=()

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

_nbfc__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
}

_nbfc__parse_commandline() {
  POSITIONALS=()
  END_OF_OPTIONS=0

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

  __find_option() {
    case "$1" in root:support*)
      case "$2" in
        --upload-firmware) VAR=OPT_upload_firmware; ARGS=0; return;;
        --print-command) VAR=OPT_print_command; ARGS=0; return;;
      esac
    esac
    case "$1" in root:acpi-dump*)
      case "$2" in
        -f|--file) VAR=OPT_file; ARGS=1; return;;
        -j|--json) VAR=OPT_json; ARGS=0; return;;
      esac
    esac
    case "$1" in root:rate-config*)
      case "$2" in
        -H|--full-help) VAR=OPT_full_help; ARGS=0; return;;
        -a|--all) VAR=OPT_all; ARGS=0; return;;
        -d|--dsdt) VAR=OPT_dsdt; ARGS=1; return;;
        -m|--min-score) VAR=OPT_min_score; ARGS=1; return;;
        -j|--json) VAR=OPT_json; ARGS=0; return;;
        --print-rules) VAR=OPT_print_rules; ARGS=0; return;;
        -r|--rules) VAR=OPT_rules; ARGS=1; return;;
        -n|--no-download) VAR=OPT_no_download; ARGS=0; return;;
      esac
    esac
    case "$1" in root:update*)
      case "$2" in
        -p|--parallel) VAR=OPT_parallel; ARGS=1; return;;
        -q|--quiet) VAR=OPT_quiet; ARGS=0; return;;
      esac
    esac
    case "$1" in root:sensors:set*)
      case "$2" in
        -f|--fan) VAR=OPT_fan; ARGS=1; return;;
        -a|--algorithm) VAR=OPT_algorithm; ARGS=1; return;;
        -s|--sensor) VAR=OPT_sensor; ARGS=1; return;;
        --force) VAR=OPT_force; ARGS=0; return;;
      esac
    esac
    case "$1" in root:set*)
      case "$2" in
        -a|--auto) VAR=OPT_auto; ARGS=0; return;;
        -s|--speed) VAR=OPT_speed; ARGS=1; return;;
        -f|--fan) VAR=OPT_fan; ARGS=1; return;;
      esac
    esac
    case "$1" in root:config*)
      case "$2" in
        -l|--list) VAR=OPT_list; ARGS=0; return;;
        -s|--set) VAR=OPT_set; ARGS=1; return;;
        -a|--apply) VAR=OPT_apply; ARGS=1; return;;
        -r|--recommend) VAR=OPT_recommend; ARGS=0; return;;
      esac
    esac
    case "$1" in root:status*)
      case "$2" in
        -a|--all) VAR=OPT_all; ARGS=0; return;;
        -s|--service) VAR=OPT_service; ARGS=0; return;;
        -f|--fan) VAR=OPT_fan; ARGS=1; return;;
        -w|--watch) VAR=OPT_watch; ARGS=1; return;;
      esac
    esac
    case "$1" in root:restart*)
      case "$2" in
        -r|--read-only) VAR=OPT_read_only; ARGS=0; return;;
      esac
    esac
    case "$1" in root:start*)
      case "$2" in
        -r|--read-only) VAR=OPT_read_only; ARGS=0; return;;
      esac
    esac
    case "$1" in root*)
      case "$2" in
        -h|--help) VAR=OPT_help; ARGS=0; return;;
        --version) VAR=OPT_version; ARGS=0; return;;
      esac
    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
        POSITIONALS+=("${words_dequoted[@]:$((++argi))}")
        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
        ;;
      *)
        POSITIONALS+=("$arg")
        case "$cmd|${#POSITIONALS[@]}" in
          'root|1') cmd+=":$arg";;
          'root:sensors|2') cmd+=":$arg";;
          'root:acpi-dump|2') cmd+=":$arg";;
        esac
        ;;
    esac
  done

  for ((; argi <= cword; ++argi)); do
    case "${words_dequoted[argi]}" in
      -?*);;
      *) POSITIONALS+=("${words_dequoted[argi]}");;
    esac
  done
}

_nbfc__exec() {
  local item desc special="$COMP_WORDBREAKS\"'><=;|&({:\\\$\`"

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

_nbfc__prefix_compreply() {
  [[ "$cur" == *[$COMP_WORDBREAKS]* ]] && return

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

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

  local END_OF_OPTIONS POSITIONALS
  local -a OPT_help OPT_version OPT_read_only OPT_all OPT_service OPT_fan
  local -a OPT_watch OPT_list OPT_set OPT_apply OPT_recommend OPT_auto OPT_speed
  local -a OPT_algorithm OPT_sensor OPT_force OPT_parallel OPT_quiet
  local -a OPT_full_help OPT_dsdt OPT_min_score OPT_json OPT_print_rules
  local -a OPT_rules OPT_no_download OPT_file OPT_upload_firmware
  local -a OPT_print_command
  _nbfc__parse_commandline

  if (( 0 < ${#POSITIONALS[@]} )); then
    case "${POSITIONALS[0]}" in
      start) _nbfc_start && return 0;;
      stop);;
      restart) _nbfc_restart && return 0;;
      status) _nbfc_status && return 0;;
      config) _nbfc_config && return 0;;
      set) _nbfc_set && return 0;;
      sensors) _nbfc_sensors && return 0;;
      update) _nbfc_update && return 0;;
      rate-config) _nbfc_rate_config && return 0;;
      acpi-dump) _nbfc_acpi_dump && return 0;;
      wait-for-hwmon);;
      get-model-name);;
      warranty);;
      support) _nbfc_support && return 0;;
      help);;
    esac
  fi

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

  (( ${#POSITIONALS[@]} == 1 )) && {
    COMPREPLY=($(compgen -W 'start stop restart status config set sensors update rate-config acpi-dump wait-for-hwmon get-model-name warranty support help' -- "$cur"))
    return 0;
  }

  return 1
}

_nbfc_start() {
  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_read_only[@]} )) && opts+=(-r --read-only)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  return 1
}

_nbfc_restart() {
  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_read_only[@]} )) && opts+=(-r --read-only)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  return 1
}

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

    case "$opt" in
      -f|--fan)
        _nbfc__exec 'nbfc complete-fans';;
      -w|--watch);;
      *) ret=1;;
    esac

    return $ret
  }

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

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

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

  return 1
}

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

    case "$opt" in
      -s|--set|-a|--apply)
        builtin pushd //usr/share/nbfc/configs &>/dev/null && {
          _filedir
          builtin popd >/dev/null
        }
        local COMPREPLY_OLD=("${COMPREPLY[@]}")
        builtin pushd /var/lib/nbfc/configs &>/dev/null && {
          _filedir
          builtin popd >/dev/null
        }
        COMPREPLY=("${COMPREPLY_OLD[@]}" "${COMPREPLY[@]}")
        local COMPREPLY_OLD=("${COMPREPLY[@]}")
        _filedir
        COMPREPLY=("${COMPREPLY_OLD[@]}" "${COMPREPLY[@]}");;
      *) ret=1;;
    esac

    return $ret
  }

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

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

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

  return 1
}

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

    case "$opt" in
      -s|--speed);;
      -f|--fan)
        _nbfc__exec 'nbfc complete-fans';;
      *) ret=1;;
    esac

    return $ret
  }

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

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

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

  return 1
}

_nbfc_sensors() {
  if (( 1 < ${#POSITIONALS[@]} )); then
    case "${POSITIONALS[1]}" in
      list);;
      show);;
      set) _nbfc_sensors_set && return 0;;
    esac
  fi

  (( ${#POSITIONALS[@]} == 2 )) && {
    COMPREPLY=($(compgen -W 'list show set' -- "$cur"))
    return 0;
  }

  return 1
}

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

    case "$opt" in
      -f|--fan)
        _nbfc__exec 'nbfc complete-fans';;
      -a|--algorithm)
        COMPREPLY=($(compgen -W 'Average Min Max' -- "$cur"));;
      -s|--sensor)
        _nbfc__exec 'nbfc complete-sensors';;
      *) ret=1;;
    esac

    return $ret
  }

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

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

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_fan[@]} )) && opts+=(-f --fan=)
    (( ! ${#OPT_algorithm[@]} )) && opts+=(-a --algorithm=)
    opts+=(-s --sensor=)
    (( ! ${#OPT_force[@]} )) && opts+=(--force)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  return 1
}

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

    case "$opt" in
      -p|--parallel);;
      *) ret=1;;
    esac

    return $ret
  }

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

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

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_parallel[@]} )) && opts+=(-p --parallel=)
    (( ! ${#OPT_quiet[@]} )) && opts+=(-q --quiet)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  return 1
}

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

    case "$opt" in
      -d|--dsdt|-r|--rules)
        _filedir;;
      -m|--min-score);;
      *) ret=1;;
    esac

    return $ret
  }

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

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

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_full_help[@]} )) && opts+=(-H --full-help)
    (( ! ${#OPT_all[@]} )) && opts+=(-a --all)
    (( ! ${#OPT_dsdt[@]} )) && opts+=(-d --dsdt=)
    (( ! ${#OPT_min_score[@]} )) && opts+=(-m --min-score=)
    (( ! ${#OPT_json[@]} )) && opts+=(-j --json)
    (( ! ${#OPT_print_rules[@]} )) && opts+=(--print-rules)
    (( ! ${#OPT_rules[@]} )) && opts+=(-r --rules=)
    (( ! ${#OPT_no_download[@]} )) && opts+=(-n --no-download)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  (( ${#POSITIONALS[@]} == 2 )) && {
    builtin pushd //usr/share/nbfc/configs &>/dev/null && {
      _filedir
      builtin popd >/dev/null
    }
    local COMPREPLY_OLD=("${COMPREPLY[@]}")
    builtin pushd /var/lib/nbfc/configs &>/dev/null && {
      _filedir
      builtin popd >/dev/null
    }
    COMPREPLY=("${COMPREPLY_OLD[@]}" "${COMPREPLY[@]}")
    local COMPREPLY_OLD=("${COMPREPLY[@]}")
    _filedir
    COMPREPLY=("${COMPREPLY_OLD[@]}" "${COMPREPLY[@]}")
    return 0;
  }

  return 1
}

_nbfc_acpi_dump() {
  if (( 1 < ${#POSITIONALS[@]} )); then
    case "${POSITIONALS[1]}" in
      registers);;
      ec-registers);;
      methods);;
      dsl);;
    esac
  fi

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

    case "$opt" in
      -f|--file)
        _filedir;;
      *) ret=1;;
    esac

    return $ret
  }

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

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

  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_file[@]} )) && opts+=(-f --file=)
    (( ! ${#OPT_json[@]} )) && opts+=(-j --json)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  (( ${#POSITIONALS[@]} == 2 )) && {
    COMPREPLY=($(compgen -W 'registers ec-registers methods dsl' -- "$cur"))
    return 0;
  }

  return 1
}

_nbfc_support() {
  if (( ! END_OF_OPTIONS )) && [[ "$cur" = -* ]]; then
    local -a opts
    (( ! ${#OPT_upload_firmware[@]} )) && opts+=(--upload-firmware)
    (( ! ${#OPT_print_command[@]} )) && opts+=(--print-command)
    COMPREPLY+=($(compgen -W "${opts[*]}" -- "$cur"))
    [[ ${COMPREPLY-} == *= ]] && compopt -o nospace
    return 1
  fi

  return 1
}

complete -F _nbfc nbfc

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