Skip to content

Conversation

@hansfn
Copy link
Contributor

@hansfn hansfn commented May 10, 2020

This is a minimal implementation which only completes the actual commands. However, new commands are automatically available for completion - no hard-coded list of command names are used. And supporting global options is easy, but handling options for each command is more work.

I was planning to add instructions to the README about sourcing drupalorg-cli-completion.sh (or adding/linking it to /etc/bash_completion.d/ but that file might not be available when installing as phar? Hm. Maybe we should do as the Github shell - ref gh completion --shell bash - add a command that just echos the file so it works for phar installs too? I'm using cgr for Composer installation so I didn't think about this problem before now ...

It should be noted that the package stecman/symfony-console-completion provides "automatic tab-key completion for Symfony console application options, arguments and parameters" but I think it's bloated for our need.

And finally: I'm not using Zsh so I haven't tried to support it, but it might not be much work.

PS! Creating this patch took me longer than anticipated because of the colons in the commands names - colons are breakwords in Bash. The solution was easy enough.

@mglaman
Copy link
Owner

mglaman commented May 10, 2020

I can test zsh. And I like the idea of what GitHub's CLI recommends – adding the eval in your profile. I know Platform.sh uses stecman/symfony-console-completion and has a command for completion and installation.

But there are way more commands and arguments, I agree it may not be necessary here. We can at least borrow the zsh bit

https://github.com/platformsh/platformsh-cli/blob/master/src/Command/CompletionCommand.php

And the installation bit:

https://github.com/platformsh/platformsh-cli/blob/master/src/Command/Self/SelfInstallCommand.php#L100

@hansfn
Copy link
Contributor Author

hansfn commented May 10, 2020

Yes, eval in the profile / .bashrc is nice, I'm just a little bit old school and like files in in etc/bash_completion.d Using files is probably better for system commands, and not user tools like drupalorg.

If you're not able to get all of this patch into the next release, it would be nice if at least the complete command is included.

@mglaman
Copy link
Owner

mglaman commented May 12, 2020

I'm cool with getting this in. Should there just be an setup command which puts the autocomplete script in place, in /etc/bash_completion.d/?

The setup command could be useful in the feature, like storing your Drupal.org username and uid for other things.

@hansfn
Copy link
Contributor Author

hansfn commented May 12, 2020

The problem with using /etc/bash_completion.d/ is that it requires root privilege. (I like to use it, but ..) And if you anyway plan to save "Drupal.org username and uid for other things" it's better to keep everything per user.

If we decide to use eval "$(drupalorg-cli completion) like GitHub CLI, the work is almost done. Just "merge" the static file and the complete command, and we have our completion command.

I'm fine with either way.

@mglaman
Copy link
Owner

mglaman commented May 13, 2020

@hansfn want to just add README instructions for the current state and I'll merge it up?

@hansfn
Copy link
Contributor Author

hansfn commented May 13, 2020

I have updated the readme. Maybe we should say something about this not working with phar installation? I was hesitant to do it because we say that composer installation is deprecated. (Ref #40.)

@mglaman mglaman self-assigned this May 14, 2020
@mglaman
Copy link
Owner

mglaman commented May 14, 2020

We can handle phar in follow up, or as I say, let bug reports drive the roadmap

@mglaman mglaman merged commit f7573e5 into mglaman:master May 14, 2020
@hansfn hansfn deleted the autocomplete branch July 20, 2021 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants