package bashimport (shlex)// Snippet creates the bash completion script.func ( *cobra.Command) string {returnSnippetSingle(.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)) }returnfmt.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)) }returnfmt.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))}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.