# AUTOMATICALLY GENERATED by `shtab`

_shtab_tmuxp_subparsers=('load' 'shell' 'import' 'convert' 'debug-info' 'ls' 'edit' 'freeze')
_shtab_tmuxp_import_subparsers=('teamocil' 'tmuxinator')

_shtab_tmuxp_option_strings=('-h' '--help' '--version' '-V' '--log-level')
_shtab_tmuxp_load_option_strings=('-h' '--help' '-L' '-S' '-f' '-s' '--yes' '-y' '-d' '-a' '--append' '-2' '-8' '--log-file')
_shtab_tmuxp_shell_option_strings=('-h' '--help' '-S' '-L' '-c' '--best' '--pdb' '--code' '--ptipython' '--ptpython' '--ipython' '--bpython' '--use-pythonrc' '--no-startup' '--use-vi-mode' '--no-vi-mode')
_shtab_tmuxp_import_option_strings=('-h' '--help')
_shtab_tmuxp_import_teamocil_option_strings=('-h' '--help')
_shtab_tmuxp_import_tmuxinator_option_strings=('-h' '--help')
_shtab_tmuxp_convert_option_strings=('-h' '--help' '--yes' '-y')
_shtab_tmuxp_debug_info_option_strings=('-h' '--help')
_shtab_tmuxp_ls_option_strings=('-h' '--help')
_shtab_tmuxp_edit_option_strings=('-h' '--help')
_shtab_tmuxp_freeze_option_strings=('-h' '--help' '-S' '-L' '-f' '--workspace-format' '-o' '--save-to' '--yes' '-y' '--quiet' '-q' '--force')

_shtab_tmuxp_load_pos_0_COMPGEN=_shtab_compgen_files
_shtab_tmuxp_load__f_COMPGEN=_shtab_compgen_files
_shtab_tmuxp_load___log_file_COMPGEN=_shtab_compgen_files
_shtab_tmuxp_import_teamocil_pos_0_COMPGEN=_shtab_compgen_files
_shtab_tmuxp_import_tmuxinator_pos_0_COMPGEN=_shtab_compgen_files
_shtab_tmuxp_convert_pos_0_COMPGEN=_shtab_compgen_files

_shtab_tmuxp_pos_0_choices=('load' 'shell' 'import' 'convert' 'debug-info' 'ls' 'edit' 'freeze')
_shtab_tmuxp___log_level_choices=('debug' 'info' 'warning' 'error' 'critical')
_shtab_tmuxp_import_pos_0_choices=('teamocil' 'tmuxinator')
_shtab_tmuxp_freeze__f_choices=('yaml' 'json')
_shtab_tmuxp_freeze___workspace_format_choices=('yaml' 'json')

_shtab_tmuxp_pos_0_nargs=A...
_shtab_tmuxp__h_nargs=0
_shtab_tmuxp___help_nargs=0
_shtab_tmuxp___version_nargs=0
_shtab_tmuxp__V_nargs=0
_shtab_tmuxp_load_pos_0_nargs=+
_shtab_tmuxp_load__h_nargs=0
_shtab_tmuxp_load___help_nargs=0
_shtab_tmuxp_load___yes_nargs=0
_shtab_tmuxp_load__y_nargs=0
_shtab_tmuxp_load__d_nargs=0
_shtab_tmuxp_load__a_nargs=0
_shtab_tmuxp_load___append_nargs=0
_shtab_tmuxp_load__2_nargs=0
_shtab_tmuxp_load__8_nargs=0
_shtab_tmuxp_shell__h_nargs=0
_shtab_tmuxp_shell___help_nargs=0
_shtab_tmuxp_shell___best_nargs=0
_shtab_tmuxp_shell___pdb_nargs=0
_shtab_tmuxp_shell___code_nargs=0
_shtab_tmuxp_shell___ptipython_nargs=0
_shtab_tmuxp_shell___ptpython_nargs=0
_shtab_tmuxp_shell___ipython_nargs=0
_shtab_tmuxp_shell___bpython_nargs=0
_shtab_tmuxp_shell___use_pythonrc_nargs=0
_shtab_tmuxp_shell___no_startup_nargs=0
_shtab_tmuxp_shell___use_vi_mode_nargs=0
_shtab_tmuxp_shell___no_vi_mode_nargs=0
_shtab_tmuxp_import_pos_0_nargs=A...
_shtab_tmuxp_import__h_nargs=0
_shtab_tmuxp_import___help_nargs=0
_shtab_tmuxp_import_teamocil__h_nargs=0
_shtab_tmuxp_import_teamocil___help_nargs=0
_shtab_tmuxp_import_tmuxinator__h_nargs=0
_shtab_tmuxp_import_tmuxinator___help_nargs=0
_shtab_tmuxp_convert__h_nargs=0
_shtab_tmuxp_convert___help_nargs=0
_shtab_tmuxp_convert___yes_nargs=0
_shtab_tmuxp_convert__y_nargs=0
_shtab_tmuxp_debug_info__h_nargs=0
_shtab_tmuxp_debug_info___help_nargs=0
_shtab_tmuxp_ls__h_nargs=0
_shtab_tmuxp_ls___help_nargs=0
_shtab_tmuxp_edit__h_nargs=0
_shtab_tmuxp_edit___help_nargs=0
_shtab_tmuxp_freeze__h_nargs=0
_shtab_tmuxp_freeze___help_nargs=0
_shtab_tmuxp_freeze___yes_nargs=0
_shtab_tmuxp_freeze__y_nargs=0
_shtab_tmuxp_freeze___quiet_nargs=0
_shtab_tmuxp_freeze__q_nargs=0
_shtab_tmuxp_freeze___force_nargs=0


# $1=COMP_WORDS[1]
_shtab_compgen_files() {
  compgen -f -- $1  # files
}

# $1=COMP_WORDS[1]
_shtab_compgen_dirs() {
  compgen -d -- $1  # recurse into subdirs
}

# $1=COMP_WORDS[1]
_shtab_replace_nonword() {
  echo "${1//[^[:word:]]/_}"
}

# set default values (called for the initial parser & any subparsers)
_set_parser_defaults() {
  local subparsers_var="${prefix}_subparsers[@]"
  sub_parsers=${!subparsers_var-}

  local current_option_strings_var="${prefix}_option_strings[@]"
  current_option_strings=${!current_option_strings_var}

  completed_positional_actions=0

  _set_new_action "pos_${completed_positional_actions}" true
}

# $1=action identifier
# $2=positional action (bool)
# set all identifiers for an action's parameters
_set_new_action() {
  current_action="${prefix}_$(_shtab_replace_nonword $1)"

  local current_action_compgen_var=${current_action}_COMPGEN
  current_action_compgen="${!current_action_compgen_var-}"

  local current_action_choices_var="${current_action}_choices[@]"
  current_action_choices="${!current_action_choices_var-}"

  local current_action_nargs_var="${current_action}_nargs"
  if [ -n "${!current_action_nargs_var-}" ]; then
    current_action_nargs="${!current_action_nargs_var}"
  else
    current_action_nargs=1
  fi

  current_action_args_start_index=$(( $word_index + 1 - $pos_only ))

  current_action_is_positional=$2
}

# Notes:
# `COMPREPLY`: what will be rendered after completion is triggered
# `completing_word`: currently typed word to generate completions for
# `${!var}`: evaluates the content of `var` and expand its content as a variable
#     hello="world"
#     x="hello"
#     ${!x} -> ${hello} -> "world"
_shtab_tmuxp() {
  local completing_word="${COMP_WORDS[COMP_CWORD]}"
  local completed_positional_actions
  local current_action
  local current_action_args_start_index
  local current_action_choices
  local current_action_compgen
  local current_action_is_positional
  local current_action_nargs
  local current_option_strings
  local sub_parsers
  COMPREPLY=()

  local prefix=_shtab_tmuxp
  local word_index=0
  local pos_only=0 # "--" delimeter not encountered yet
  _set_parser_defaults
  word_index=1

  # determine what arguments are appropriate for the current state
  # of the arg parser
  while [ $word_index -ne $COMP_CWORD ]; do
    local this_word="${COMP_WORDS[$word_index]}"

    if [[ $pos_only = 1 || " $this_word " != " -- " ]]; then
      if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then
        # valid subcommand: add it to the prefix & reset the current action
        prefix="${prefix}_$(_shtab_replace_nonword $this_word)"
        _set_parser_defaults
      fi

      if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then
        # a new action should be acquired (due to recognised option string or
        # no more input expected from current action);
        # the next positional action can fill in here
        _set_new_action $this_word false
      fi

      if [[ "$current_action_nargs" != "*" ]] && \
         [[ "$current_action_nargs" != "+" ]] && \
         [[ "$current_action_nargs" != *"..." ]] && \
         (( $word_index + 1 - $current_action_args_start_index - $pos_only >= \
            $current_action_nargs )); then
        $current_action_is_positional && let "completed_positional_actions += 1"
        _set_new_action "pos_${completed_positional_actions}" true
      fi
    else
      pos_only=1 # "--" delimeter encountered
    fi

    let "word_index+=1"
  done

  # Generate the completions

  if [[ $pos_only = 0 && "${completing_word}" == -* ]]; then
    # optional argument started: use option strings
    COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") )
  else
    # use choices & compgen
    local IFS=$'\n' # items may contain spaces, so delimit using newline
    COMPREPLY=( $([ -n "${current_action_compgen}" ] \
                  && "${current_action_compgen}" "${completing_word}") )
    unset IFS
    COMPREPLY+=( $(compgen -W "${current_action_choices[*]}" -- "${completing_word}") )
  fi

  return 0
}

complete -o filenames -F _shtab_tmuxp tmuxp
