package bashimport (shlex)// RedirectError current position is a redirect like `echo test >[TAB]`.typeRedirectErrorstruct{}func ( RedirectError) () string {return"current position is a redirect like `echo test >[TAB]`"}// TODO yuck! - set by Patch which also unsets bash comp environment variables so that they don't affect further completion// introduces state and hides what is happening but works for nowvar wordbreakPrefix string = ""func () (string, bool) { , := os.LookupEnv("COMP_LINE")if ! {return"", false } , := os.LookupEnv("COMP_POINT")if ! {return"", false } , := strconv.Atoi()if != nil || len() < {return"", false }return [:], true}// Patch patches args if `COMP_LINE` environment variable is set.//// Bash passes redirects to the completion function so these need to be filtered out.//// `example action >/tmp/stdout.txt --values 2>/tmp/stderr.txt fi[TAB]`// ["example", "action", ">", "/tmp/stdout.txt", "--values", "2", ">", "/tmp/stderr.txt", "fi"]// ["example", "action", "--values", "fi"]func ( []string) ([]string, error) { // TODO document and fix wordbreak splitting (e.g. `:`) , := CompLine()if ! {return , nil }if == "" {return , nil } , := shlex.Split()if != nil {returnnil, }iflen() > 1 {if := [len()-2]; .WordbreakType.IsRedirect() {returnappend([:1], [len()-1].Value), RedirectError{} } } = append([:1], .CurrentPipeline().FilterRedirects().Words().Strings()...)// TODO find a better solution to pass the wordbreakprefix to bash/action.gowordbreakPrefix = .CurrentPipeline().WordbreakPrefix()unsetBashCompEnv()return , nil}func unsetBashCompEnv() {for , := range []string{// https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html"COMP_CWORD","COMP_LINE","COMP_POINT","COMP_TYPE","COMP_KEY","COMP_WORDBREAKS","COMP_WORDS", } {os.Unsetenv() }}
The pages are generated with Goldsv0.8.2. (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.