Open synfinatic opened 1 year ago
Thanks for the feature request. I spent some time looking into this, and it isn't straight forward.
First off, there isn't a good way to get the completion for the next command from within a Go program because it doesn't have access to the shell it was run from. The closest I see is for bash is something like exec.Command("bash", "-ilc", "your script here")
. That will run your script in an interactive login shell, so you would be able to run complete
and compgen
, but you wouldn't have access to any completions the user registered in .bash_profile
or anywhere else -- and .bash_profile
is the usual entry point for bash completions.
With that eliminated, we need to register a completion outside of the go program. I came up with something that works for testme exec --myflag foo --
, but it only works for bash and requires that the user use "--" to separate testme exec
args from the command they are executing. The same idea could be applied to other shells, and I'm pretty sure you can get past the "--" requirement with some more clever shell scripting.
I haven't done any significant testing of this, so it's status is strictly "works on my machine". I'm not sure if I would want to incorporate something like this into kongplete or not. It's more shell scripting than I want to be responsible for maintaining. I might just make it easier to hook custom scripts into install completions and use this as an example.
I will probably be adding an exec command to bindown soon, so I'm interested in seeing what you come up with.
So my program behaves a bit like sudo. Ie: you can use it to exec other commands. Technically it does it as a sub-command, ie:
aws-sso exec [flags] <command> [flags]
Doesn't seem to be a way to tell kongplete to do basically what sudo does? https://github.com/scop/bash-completion/blob/master/completions/sudo#L17