package bash

import (
	
	

	shlex 
	
	
)

// Snippet creates the bash completion script.
func ( *cobra.Command) string {
	return SnippetSingle(.Name(), false)
}

// SnippetMulti creates a multi-completer bash completion script.
func ( []string,  string,  string) string {
	 := make([]string, 0, len())
	for ,  := range  {
		 = append(, shlex.Quote(, shlex.Bash))
	}
	return fmt.Sprintf(`#!/bin/bash
%[4]v_%[1]v_completer() {
  export COMP_LINE
  export COMP_POINT
  export COMP_TYPE
  export COMP_WORDBREAKS

  local nospace data compline="${COMP_LINE:0:${COMP_POINT}}"
  local command="${COMP_WORDS[0]}"

  data=$(echo "${compline}''" | CARAPACE_COMPLINE="${compline}" xargs %[2]v "${command}" _carapace bash 2>/dev/null)
  if [ $? -eq 1 ]; then
    data=$(echo "${compline}'" | CARAPACE_COMPLINE="${compline}" xargs %[2]v "${command}" _carapace bash 2>/dev/null)
    if [ $? -eq 1 ]; then
    	data=$(echo "${compline}\"" | CARAPACE_COMPLINE="${compline}" xargs %[2]v "${command}" _carapace bash 2>/dev/null)
    fi
  fi

  IFS=$'\001' read -r -d '' nospace data <<<"${data}"
  mapfile -t COMPREPLY < <(echo "${data}")
  unset COMPREPLY[-1]

  [ "${nospace}" = true ] && compopt -o nospace
  local IFS=$'\n'
  [[ "${COMPREPLY[*]}" == "" ]] && COMPREPLY=() # fix for mapfile creating a non-empty array from empty command output
}

complete -o noquote -F _%[1]v_completer %[3]v
`, , shlex.Quote(uid.Executable(), shlex.Bash), strings.Join(, " "), )
}

// SnippetSingle creates a single-command bash completion script.
// When explicitCommand is true, the command name is included in the invocation
// (for multi-completer subcommands). When false, the executable is invoked
// without an explicit command (standalone mode).
func ( string,  bool) string {

	 := fmt.Sprintf("%v _carapace bash", shlex.Quote(uid.Executable(), shlex.Bash))
	if  {
		 = fmt.Sprintf("%v %v _carapace bash", shlex.Quote(uid.Executable(), shlex.Bash), shlex.Quote(, shlex.Bash))
	}

	return fmt.Sprintf(`#!/bin/bash
_%[1]v_completion() {
  export COMP_LINE
  export COMP_POINT
  export COMP_TYPE
  export COMP_WORDBREAKS

  local nospace data compline="${COMP_LINE:0:${COMP_POINT}}"

  data=$(echo "${compline}''" | CARAPACE_COMPLINE="${compline}" xargs %[2]v 2>/dev/null)
  if [ $? -eq 1 ]; then
    data=$(echo "${compline}'" | CARAPACE_COMPLINE="${compline}" xargs %[2]v 2>/dev/null)
    if [ $? -eq 1 ]; then
    	data=$(echo "${compline}\"" | CARAPACE_COMPLINE="${compline}" xargs %[2]v 2>/dev/null)
    fi
  fi

  IFS=$'\001' read -r -d '' nospace data <<<"${data}"
  mapfile -t COMPREPLY < <(echo "${data}")
  unset COMPREPLY[-1]

  [ "${nospace}" = true ] && compopt -o nospace
  local IFS=$'\n'
  [[ "${COMPREPLY[*]}" == "" ]] && COMPREPLY=() # fix for mapfile creating a non-empty array from empty command output
}

complete -o noquote -F _%[1]v_completion %[3]v
`, , , shlex.Quote(, shlex.Bash))
}