New fully featured bash completion for go - written in go

1,529 views
Skip to first unread message

Eyal Posener

unread,
May 13, 2017, 4:29:47 AM5/13/17
to golang-nuts
Simple to install (Assuming GOPATH and PATH are correct):

go install github.com/posener/complete/gocomplete
gocomplete
-install

Features:
  • Complete go command, sub commands and flags.
  • Complete package names, .go files and ellipsis when necessary.
  • Complete test names after -run flag!
Works with bash / zsh shells

This is also a package, that enables writing bash completion scripts, or add them to an existing go program.

Please, open issues, contribute and star!

Jonathan Yu

unread,
May 13, 2017, 3:03:25 PM5/13/17
to Eyal Posener, golang-nuts
Nifty! Do the bash completion scripts need to be dynamically regenerated? I guess so for some of the features like completing on package names.

It seems useful to have some Go completions (e.g. go in<TAB> == go install) available as part of distro packages.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Jonathan Yu @jawnsy on LinkedInTwitterGitHubFacebook
“Ever tried. Ever failed. No matter. Try again. Fail again. Fail better.” — Samuel Beckett, Worstward Ho (1983) 

“In an adaptive environment, winning comes from adapting to change by continuously experimenting and identifying new options more quickly and economically than others. The classical strategist's mantra of sustainable competitive advantage becomes one of serial temporary advantage.” — Navigating the Dozens of Different Strategy Options (HBR)

Eyal Posener

unread,
May 13, 2017, 3:26:47 PM5/13/17
to golang-nuts, pos...@gmail.com
Thanks!

On Saturday, May 13, 2017 at 10:03:25 PM UTC+3, Jonathan Yu wrote:
Nifty! Do the bash completion scripts need to be dynamically regenerated? I guess so for some of the features like completing on package names.

Not sure I understand your question, but the bash completion script does not need to be regenerated.
What happens under the hood is that there is a go binary that completes the next word. the go binary is called by the shell when the tab key is pressed.
What that tells the shell to call that binary for completion is a line in the bashrc or zshrc, which does not need to be changed, and is added when you type `gocomplete -install`. 

It seems useful to have some Go completions (e.g. go in<TAB> == go install) available as part of distro packages.
On Sat, May 13, 2017 at 1:29 AM, Eyal Posener <pos...@gmail.com> wrote:
Simple to install (Assuming GOPATH and PATH are correct):

go install github.com/posener/complete/gocomplete
gocomplete
-install

Features:
  • Complete go command, sub commands and flags.
  • Complete package names, .go files and ellipsis when necessary.
  • Complete test names after -run flag!
Works with bash / zsh shells

This is also a package, that enables writing bash completion scripts, or add them to an existing go program.

Please, open issues, contribute and star!

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Frank Schröder

unread,
May 13, 2017, 8:58:37 PM5/13/17
to golang-nuts, pos...@gmail.com
This is awesome. I've immediately started working on https://github.com/magiconair/consulcomplete :)

Frank

Eyal Posener

unread,
May 14, 2017, 1:46:38 AM5/14/17
to golang-nuts, pos...@gmail.com
Frank, sweet!

Notice that you can build custom completions, such as completing agent names in consul exec -node <node-name> and service names after -service and so on.
Also, you may suggest to add this code to the main consul repo.

Frank Schröder

unread,
May 14, 2017, 2:06:45 AM5/14/17
to Eyal Posener, golang-nuts
I'll look into this. So far I've spent 30 min on this. :) which dir pattern should I use for directory completions so that the suggestions don't start with ./ ?

Eg consul agent -server -data-dir ./data

Frank Schröder
--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/ZcbRJuJJrsI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

Eyal Posener

unread,
May 14, 2017, 3:04:11 AM5/14/17
to golang-nuts, pos...@gmail.com


On Sunday, May 14, 2017 at 9:06:45 AM UTC+3, Frank Schröder wrote:
I'll look into this. So far I've spent 30 min on this. :) which dir pattern should I use for directory completions so that the suggestions don't start with ./ ?

currently all relative directories are completed with the `./` prefix, Does it make any problems? 

Frank Schröder

unread,
May 14, 2017, 3:30:57 AM5/14/17
to Eyal Posener, golang-nuts
It's not how other completions work, it's redundant and makes it harder to read.

Frank Schröder

mhh...@gmail.com

unread,
May 14, 2017, 7:08:16 AM5/14/17
to golang-nuts
looks awesome!!

In this,
https://github.com/posener/complete/blob/master/example/self/main.go

Just wonder why i can t simply do something similar to,


var name string
whatever
.StringVar(&name, "name", "", "Give your name", complete.PredictAnything)

if whatever.Run() {
return
}

Anyway, great stuff here!

Eyal Posener

unread,
May 14, 2017, 9:58:57 AM5/14/17
to golang-nuts, pos...@gmail.com
Sure, open an issue, I'll fix that

Eyal Posener

unread,
May 15, 2017, 9:43:48 AM5/15/17
to golang-nuts
The right installation commands are:

go get github.com/posener/complete/gocomplete
gocomplete -install

You can also view the code in https://github.com/posener/complete

Reply all
Reply to author
Forward
0 new messages