Skip to content
Myr

Enable bash completions on Macs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

If they installed bash-completions from homebrew, this should make our completions work.

authored by Eric Paris · committed by Eric Paris · parent 16b4170 · Browse files · 1 file+14 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+14 added−3 removed

  • other:+14 added−3 removed

1 file+14 added−3 removed

modified:bash_completions.go+14 added-3 removed
17 unmodified lines
1819func preamble(out *bytes.Buffer) {20 fmt.Fprintf(out, `#!/bin/bash212222__debug()23{24 if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then25 echo "$*" >> "${BASH_COMP_DEBUG_FILE}"26 fi27}2829# Homebrew on Macs have version 1.3 of bash-completion which doesn't include30# _init_completion. This is a very minimal version of that function.31__my_init_completion()32{33 COMPREPLY=()34 _get_comp_words_by_ref cur prev words cword35}3637__index_of_word()38{39 local w word=$140 shift
153 unmodified lines
194func postscript(out *bytes.Buffer, name string) {195 fmt.Fprintf(out, "__start_%s()\n", name)196 fmt.Fprintf(out, `{197 local cur prev words cword198 if declare -F _init_completions >/dev/null 2>&1; then191 _init_completion -s || return199 _init_completion -s || return200 else201 __my_init_completion || return202 fi203204 local c=0205 local flags=()206 local two_word_flags=()
95 unmodified lines
302func writeRequiredFlag(cmd *Command, out *bytes.Buffer) {303 fmt.Fprintf(out, " must_have_one_flag=()\n")304 flags := cmd.NonInheritedFlags()305 flags.VisitAll(func(flag *pflag.Flag) {295 for key, _ := range flag.Annotations {306 for key := range flag.Annotations {307 switch key {308 case BashCompOneRequiredFlag:309 format := " must_have_one_flag+=(\"--%s"310 b := (flag.Value.Type() == "bool")
88 unmodified lines