-
Notifications
You must be signed in to change notification settings - Fork 6
feat(cmd/dbc): add custom shell completions #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Works in zsh on macOS! Would it be possible to implement something like |
|
Awesome! I've been playing around a bit with Fish on Linux. As a note, there were some parts that didn't seem to work perfectly. Maybe the files shouldn't be listed? $ ./dbc
add (Add a driver to the driver list) docs/ pixi.toml
ci/ drivers.go README.md
# snipSeems lack $ ./dbc comSeems lack $ ./dbc add -
-h (Help) -p --path (Driver list to add to) |
|
@eitsupi I've updated the scripts based on your feedback, let me know what you think! |
|
Thanks for this @zeroshade. I'm not totally keen on having a dedicated subcommand for managing completions, I think it competes for space with our other subcommands and it's not in the same category as the others. Are there other tools that use a dedicated subcommand like this? As for the completions themselves, I'm still seeing files in the current working directory when I tab like @eitsupi did. Is that expected? |
I'll have to play with fish a bit to figure that out, I'm not seeing that behavior with bash
Or in zsh
So let me see what I have to change for fish |
|
okay, i found the right option and tested it. I got it to stop giving files as suggestions! give it a try |
|
I've also updated the config for linux packages to auto include the auto complete scripts so if you install via deb/rpm it will automatically install the tab completion scripts for all three shells |
|
Nice, that fixes the issue for me. What do you think about my comment about whether we should actually have a completion subcommand or just handle this entirely through packaging? |
|
While I added some stuff for the linux package packaging, my preference is still to include the |
|
That's interesting. Their CLI utility somehow lets them have hidden subcommands. Can we do that without too much hackery? |
|
I suppose our mainprog can just handle it as a special case outside the main handling. |
|
There are other CLI option libraries, I went with So if it's important, we can add the feature to go-arg (I don't think it'd be too hard) or we can switch over to using a different CLI library like cobra or something else which does have that feature |
We use |
|
Ah, gotcha. If it's not too much trouble to swap out go-arg for cobra, I'd really like us not to have a visible shell completions subcommand in our help output. |
|
swapping out go-arg for cobra (which I believe still shows the |
|
Okay, that's not ideal then. How gross is this? diff --git a/cmd/dbc/main.go b/cmd/dbc/main.go
index e9c9b89..0b971a5 100644
--- a/cmd/dbc/main.go
+++ b/cmd/dbc/main.go
@@ -142,6 +142,12 @@ var prog *tea.Program
func main() {
var args cmds
+ // Handle generate-shell-completion
+ if len(os.Args) >= 2 && os.Args[1] == "generate-shell-completion" {
+ fmt.Println("TODO: Implement me")
+ return
+ }
+
p := arg.MustParse(&args)
if p.Subcommand() == nil {
p.WriteHelp(os.Stdout)
|
|
pretty gross... I can take a look at what it would take to add "hidden" command abilities to go-arg and file a PR there? he seems responsive |
|
that would be really great, thanks @zeroshade |
|
@amoeba I filed a PR (alexflint/go-arg#292) on go-arg, but for now I've pointed this to use my forked branch with the change so you can test it out and let me know what you think. |
clap has the ability to add subcommands like this, which I think is very common among Rust CLI tools. For example, |
|
I've played around a bit with the latest version and it looks pretty good. Awesome! I'm not sure if the |
|
@eitsupi my latest change removed it from the top-level help. Any other comments here? |
|
I missed this when I first looked at this but I'm not liking that the current approach installs completions system-wide for bash and zsh. fish looks fine. Do bash and zsh not have user completions.d dirs? Alternatively, we could document simpler install instructions, I'll push up an example of what I think will work. |
|
As far as I could tell there's no automatic place where local user completions will be picked up for bash/zsh without explicitly adding the path to that location to your |
eitsupi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you.
Well, aside from how I documented it in c7324fc. Do you like that at all? I personally don't like anything dynamic in my shell config but there are too many tools that mandate it (like conda). |
|
I'm good with the additions to the docs you added. that looks good to me |
|
Okay, I updated the completion help output to show that method too and added a note in the installation page about accessing the help output in case users want more help than what the docs give. |



closes #86
First pass at creating custom shell tab-completion scripts for bash/zsh/fish via
dbc completion <shell>If you do
dbc completion <shell> -hit'll also explain how to use the auto completion script for that shell.