# 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

function _nbfc__query

  set -l positionals
  set -l having_options
  set -l option_values

  set -l options $argv[1]
  set -e argv[1]

  set -l cmd $argv[1]
  set -e argv[1]

  set -l my_cache_key "$(commandline -b) $options"

  if test "$__QUERY_CACHE_KEY" = "$my_cache_key"
    set positionals    $__QUERY_CACHE_POSITIONALS
    set having_options $__QUERY_CACHE_HAVING_OPTIONS
    set option_values  $__QUERY_CACHE_OPTION_VALUES
  else

    set -l short_opts_with_arg
    set -l short_opts_without_arg
    set -l short_opts_with_optional_arg
    set -l long_opts_with_arg
    set -l long_opts_without_arg
    set -l long_opts_with_optional_arg

    set -l option

    if test -n "$options"
      for option in (string split -- ' ' $options)
        if false
          true
        else if string match -qr -- '^--.+=$' $option
          set -a long_opts_with_arg (string replace -- '=' '' $option)
        else if string match -qr -- '^--.+=\?$' $option
          set -a long_opts_with_optional_arg (string replace -- '=?' '' $option)
        else if string match -qr -- '^--.+$' $option
          set -a long_opts_without_arg $option
        else if string match -qr -- '^-.=$' $option
          set -a short_opts_with_arg (string replace -- '=' '' $option)
        else if string match -qr -- '^-.=\?$' $option
          set -a short_opts_with_optional_arg (string replace -- '=?' '' $option)
        else if string match -qr -- '^-.$' $option
          set -a short_opts_without_arg $option
        end
      end
    end

    set -l cmdline (commandline -poc)
    set -l cmdline_count (count $cmdline)

    set -l argi 2 # cmdline[1] is command name
    while test $argi -le $cmdline_count
      set -l arg "$cmdline[$argi]"
      set -l have_trailing_arg (test $argi -lt $cmdline_count && echo true || echo false)

      switch $arg
        case '-'
          set -a positionals -
        case '--'
          set -a positionals $cmdline[$(math $argi + 1)..]
          break
        case '--*=*'
          set -l split (string split -m 1 -- '=' $arg)
          set -a having_options $split[1]
          set -a option_values "$split[2]"
        case '--*'
          if contains -- $arg $long_opts_with_arg
            if $have_trailing_arg
              set -a having_options $arg
              set -a option_values $cmdline[(math $argi + 1)]
              set argi (math $argi + 1)
            end
          else
            set -a having_options $arg
            set -a option_values ''
          end
        case '-*'
          set -l end_of_parsing false

          set -l arg_length (string length -- $arg)
          set -l i 2
          while not $end_of_parsing; and test $i -le $arg_length
            set -l option "-$(string sub -s $i -l 1 -- $arg)"
            set -l trailing_chars "$(string sub -s (math $i + 1) -- $arg)"

            if contains -- $option $short_opts_without_arg
              set -a having_options $option
              set -a option_values ''
            else if contains -- $option $short_opts_with_arg
              set end_of_parsing true

              if test -n "$trailing_chars"
                set -a having_options $option
                set -a option_values $trailing_chars
              else if $have_trailing_arg
                set -a having_options $option
                set -a option_values $cmdline[(math $argi + 1)]
                set argi (math $argi + 1)
              end
            else if contains -- $option $short_opts_with_optional_arg
              set end_of_parsing true
              set -a having_options $option
              set -a option_values "$trailing_chars" # may be empty
            end

            set i (math $i + 1)
          end
        case '*'
          set -a positionals $arg
      end

      set argi (math $argi + 1)
    end

    set -g __QUERY_CACHE_POSITIONALS    $positionals
    set -g __QUERY_CACHE_HAVING_OPTIONS $having_options
    set -g __QUERY_CACHE_OPTION_VALUES  $option_values
    set -g __QUERY_CACHE_KEY            $my_cache_key
  end

  switch $cmd
    case 'positional_contains'
      set -l positional_num $argv[1]
      set -e argv[1]
      contains -- $positionals[$positional_num] $argv && return 0 || return 1
    case 'has_option'
      for option in $having_options
        contains -- $option $argv && return 0
      end

      return 1
    case 'num_of_positionals'
      switch (count $argv)
        case 0
          count $positionals
        case 2
          if contains -- $argv[1] -lt -le -eq -ne -gt -ge;
            test (count $positionals) $argv[1] $argv[2] && return 0 || return 1
          end
      end
  end
end

function _nbfc__filedir

  argparse --max-args 0 'd/description=' 'D/directories' 'C/cd=' \
      -- $argv || return 1

  set -l comp (_nbfc__get_completing_arg)
  set -l desc
  set -l files

  if set -q _flag_cd[1]
    pushd $_flag_cd 2>/dev/null || return 1
    set files (complete -C"'' $comp")
    popd
  else
    set files (complete -C"'' $comp")
  end

  if set -q _flag_description[1]
    set desc $_flag_description
  else if set -g _flag_directories
    set desc 'Directory'
  end

  if set -q files[1]
    if set -q _flag_directories[1]
      set files (printf '%s\n' $files | string match -r '.*/$')
    end

    printf '%s\n' $files\t"$desc"
  end
end

function _nbfc__get_completing_arg
  set -l arg (commandline -ct | string unescape)

  switch $arg
    case '--*=' '--*=*'
      set arg (string replace -r -- '^-[^=]*=' '' $arg)
    case '-*'
      set -l prog (commandline -po)[1]
      set -l progdef (complete -c $prog)

      set -l full_opt (string match -r -- '^-[a-zA-Z0-9]+=' $arg)
      set -l opt (string sub -s 2 -e -1 -- $full_opt)
      set -l optdefs (string match -re -- " -(o|-old-option) $opt( |\$)" $progdef)
      set -l optdefs (string match -re -- " -(x|r|a|-(exclusive|require-parameter|arguments))( |\$)" $optdefs)

      if test (count $optdefs) -gt 0
        set arg (string replace -m 1 -- $full_opt '' $arg)
      else
        set -l i 2

        while test $i -lt (string length -- $arg)
          set -l opt (string sub -s $i -l 1 -- $arg)
          set -l optdefs (string match -re -- " -(s|-short-option) $opt( |\$)" $progdef)
          set -l optdefs (string match -re -- " -(x|r|a|-(exclusive|require-parameter|arguments))( |\$)" $optdefs)

          if test (count $optdefs) -gt 0
            set arg (string sub -s (math $i + 1) -- "$arg")
            break
          end

          set i (math $i + 1)
        end
      end
  end

  if test -n "$__fish_stripprefix"
    string replace -r -- $__fish_stripprefix '' "$arg"
  else
    printf '%s\n' "$arg"
  end
end

function _nbfc_sensors__command
  printf '%s\t%s\n' \
    list 'List available sensors and temperature files' \
    show 'Show all available fans with their configuration' \
    set 'Configure sensors and algorithm type for a fan'
end

function _nbfc_acpi_dump__command
  printf '%s\t%s\n' \
    registers 'List all available registers' \
    ec-registers 'List all available EC registers' \
    methods 'List all available ACPI methods' \
    dsl 'Disassemble your DSDT'
end

function _nbfc__command
  printf '%s\t%s\n' \
    start 'Start the service' \
    stop 'Stop the service' \
    restart 'Restart the service' \
    status 'Show the service status' \
    config 'List or apply configs' \
    set 'Control fan speed' \
    sensors 'Configure fan sensors' \
    update 'Download new configuration files' \
    rate-config 'Rate a configuration file' \
    acpi-dump 'Dumps information of your ACPI DSDT' \
    wait-for-hwmon 'Wait for /sys/class/hwmon/hwmon* files' \
    get-model-name 'Print model name for notebook' \
    warranty 'Show warranty' \
    support 'Show how to support the project' \
    help 'Show help'
end

set -l prog 'nbfc'
set -l query '_nbfc__query'

# Delete existing completions
complete -c $prog -e

# Generally disable file completion
complete -c $prog -x

# command nbfc
set -l opts "-h --help --version"
set -l C000 "not $query '$opts' has_option -h --help"
set -l C001 "not $query '$opts' has_option --version"
set -l C002 "$query '$opts' num_of_positionals -eq 0"
complete -c $prog -n $C000 -s h -l help -d 'show this help message and exit' -f
complete -c $prog -n $C001 -l version -d "show program's version number and exit" -f
complete -c $prog -n $C002 -d Commands -f -a '(_nbfc__command)'

# command nbfc start
set -l opts "-r --read-only -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 start && not $query '$opts' has_option -r --read-only"
complete -c $prog -n $C000 -s r -l read-only -d 'Start in read-only mode' -f

# command nbfc restart
set -l opts "-r --read-only -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 restart && not $query '$opts' has_option -r --read-only"
complete -c $prog -n $C000 -s r -l read-only -d 'Restart in read-only mode' -f

# command nbfc status
set -l opts "-a --all -s --service -f= --fan= -w= --watch= -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 status && not $query '$opts' has_option -s --service -f --fan -a --all"
set -l C001 "$query '$opts' positional_contains 1 status && not $query '$opts' has_option -a --all -f --fan -s --service"
set -l C002 "$query '$opts' positional_contains 1 status && not $query '$opts' has_option -a --all -s --service -f --fan"
set -l C003 "$query '$opts' positional_contains 1 status && not $query '$opts' has_option -w --watch"
complete -c $prog -n $C000 -s a -l all -d 'Show service and fan status (default)' -f
complete -c $prog -n $C001 -s s -l service -d 'Show service status' -f
complete -c $prog -n $C002 -s f -l fan -d 'Show status of fan (zero based)' -x -a '(nbfc complete-fans)'
complete -c $prog -n $C003 -s w -l watch -d 'Show status periodically' -x

# command nbfc config
set -l opts "-l --list -s= --set= -a= --apply= -r --recommend -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 config && not $query '$opts' has_option -s --set -a --apply -r --recommend -l --list"
set -l C001 "$query '$opts' positional_contains 1 config && not $query '$opts' has_option -l --list -a --apply -r --recommend -s --set"
set -l C002 "$query '$opts' positional_contains 1 config && not $query '$opts' has_option -l --list -s --set -r --recommend -a --apply"
set -l C003 "$query '$opts' positional_contains 1 config && not $query '$opts' has_option -l --list -s --set -a --apply -r --recommend"
complete -c $prog -n $C000 -s l -l list -d 'List all available configs (default)' -f
complete -c $prog -n $C001 -s s -l set -d 'Set a config' -x -a '(_nbfc__filedir -C //usr/share/nbfc/configs; _nbfc__filedir -C /var/lib/nbfc/configs; _nbfc__filedir)'
complete -c $prog -n $C002 -s a -l apply -d 'Set a config and enable fan control' -x -a '(_nbfc__filedir -C //usr/share/nbfc/configs; _nbfc__filedir -C /var/lib/nbfc/configs; _nbfc__filedir)'
complete -c $prog -n $C003 -s r -l recommend -d 'List configs which may work for your device' -f

# command nbfc set
set -l opts "-a --auto -s= --speed= -f= --fan= -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 set && not $query '$opts' has_option -s --speed -a --auto"
set -l C001 "$query '$opts' positional_contains 1 set && not $query '$opts' has_option -a --auto -s --speed"
set -l C002 "$query '$opts' positional_contains 1 set && not $query '$opts' has_option -f --fan"
complete -c $prog -n $C000 -s a -l auto -d "Set fan speed to 'auto'" -f
complete -c $prog -n $C001 -s s -l speed -d 'Set fan speed to PERCENT' -x
complete -c $prog -n $C002 -s f -l fan -d 'Fan index (zero based)' -x -a '(nbfc complete-fans)'

# command nbfc sensors
set -l opts "-h --help --version"
set -l C000 "$query '$opts' num_of_positionals -eq 1 && $query '$opts' positional_contains 1 sensors"
complete -c $prog -n $C000 -d Commands -f -a '(_nbfc_sensors__command)'

# command nbfc update
set -l opts "-p= --parallel= -q --quiet -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 update && not $query '$opts' has_option -p --parallel"
set -l C001 "$query '$opts' positional_contains 1 update && not $query '$opts' has_option -q --quiet"
complete -c $prog -n $C000 -s p -l parallel -d 'Set number of parallel downloads' -x
complete -c $prog -n $C001 -s q -l quiet -d 'Enable quiet mode' -f

# command nbfc rate-config
set -l opts "-H --full-help -a --all -d= --dsdt= -m= --min-score= -j --json --print-rules -r= --rules= -n --no-download -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -H --full-help"
set -l C001 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -a --all"
set -l C002 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -d --dsdt"
set -l C003 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -m --min-score"
set -l C004 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -j --json"
set -l C005 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option --print-rules"
set -l C006 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -r --rules"
set -l C007 "$query '$opts' positional_contains 1 rate-config && not $query '$opts' has_option -n --no-download"
set -l C008 "$query '$opts' num_of_positionals -eq 1 && $query '$opts' positional_contains 1 rate-config"
complete -c $prog -n $C000 -s H -l full-help -d 'Show full help' -f
complete -c $prog -n $C001 -s a -l all -d 'Rate all available configuration files' -f
complete -c $prog -n $C002 -s d -l dsdt -d 'Use an alternative DSDT file' -Fr
complete -c $prog -n $C003 -s m -l min-score -d 'Set minimum rating threshold for configurations' -x
complete -c $prog -n $C004 -s j -l json -d 'Use JSON output' -f
complete -c $prog -n $C005 -l print-rules -d 'Print configuration rules' -f
complete -c $prog -n $C006 -s r -l rules -d 'Use an alternative rules file' -Fr
complete -c $prog -n $C007 -s n -l no-download -d "Don't download rules file from the repository" -f
complete -c $prog -n $C008 -d 'Specify configuration file' -x -a '(_nbfc__filedir -C //usr/share/nbfc/configs; _nbfc__filedir -C /var/lib/nbfc/configs; _nbfc__filedir)'

# command nbfc acpi-dump
set -l opts "-f= --file= -j --json -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 acpi-dump && not $query '$opts' has_option -f --file"
set -l C001 "$query '$opts' positional_contains 1 acpi-dump && not $query '$opts' has_option -j --json"
set -l C002 "$query '$opts' num_of_positionals -eq 1 && $query '$opts' positional_contains 1 acpi-dump"
complete -c $prog -n $C000 -s f -l file -d 'Use an alternative DSDT file' -Fr
complete -c $prog -n $C001 -s j -l json -d 'Use JSON output' -f
complete -c $prog -n $C002 -d Commands -f -a '(_nbfc_acpi_dump__command)'

# command nbfc support
set -l opts "--upload-firmware --print-command -h --help --version"
set -l C000 "$query '$opts' positional_contains 1 support && not $query '$opts' has_option --upload-firmware"
set -l C001 "$query '$opts' positional_contains 1 support && not $query '$opts' has_option --print-command"
complete -c $prog -n $C000 -l upload-firmware -d 'Upload your notebook firmware without prompting' -f
complete -c $prog -n $C001 -l print-command -d 'Print command for manual firmware upload' -f

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