Skip to content
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

Add a bash-completion script #22

Open
aleksejrs opened this issue Aug 17, 2012 · 6 comments
Open

Add a bash-completion script #22

aleksejrs opened this issue Aug 17, 2012 · 6 comments

Comments

@aleksejrs
Copy link
Contributor

mozdownload has multiple command line switches, some of which are only available in the long form.
mozdownload also has 43-line help output.

bash-completion allows for auto-completion of command line options of a program when using bash or zsh. For example, git provides a 56-kilobyte description of completion in Debian (most auto-completion scripts are only a couple kilobytes though). With it, you can enter “mozdownload --”, press Tab, and see a concise list of all the available long switches; or you can enter also a couple of letters of a switch and press Tab and have that switch completed.

Most of the auto-completion scripts are written in bash itself, but there is a Perl support script, and at least one program to generate one based on Python's optparse syntax (possibly supporting or ported to argparse).

@jayrajput
Copy link
Contributor

I found this from http://www.joshmatthews.net/bugsahoy/?sh=1. I see that python optcomplete module can be used to provide automatic completion. I have forked the repo and making the changes.

Description of planned changes (Let me know if you see any issues)

  • Update setup.py to add dependency on the optcomplete python package (https://pypi.python.org/pypi/optcomplete)
  • Update code in scrapper.py to use optcomplete as suggested by optcomplete documentation.

After these two changes, user has to follow the optcomplete documentation to source a bash function and then to tell Bash to trigger optcomplete completion for the specific programs that use it:

complete -F _optcomplete <program>

Python also has argparse and argcomplete. But the Option Group is not so straightforward (atleast to me) in the argparse. The scrapper.py is using Option Group for different build (candidate, daily and tinderbox) options.

I will be doing manual testing on zsh and bash for the auto-completion of two or more options. I will also run the automated tests and make sure that they pass.

@jayrajput
Copy link
Contributor

I ended up not using optcomplete. During changes, I realized it is too much for just the simple cli switches completion.

I ended up updating the scrapper.py to provide all the options when called with the environment containing _MOZDOWNLOADARGCOMPLETE. This is the same strategy which optcomplete and argcomplete use.

I also added a bash_completion.d/python-mozdownload.sh which provides the bash completion. This is similar to argcomplete bash_completion.d file. The addition of new file needed updates in the setup.py to include package_data.

I have all the changes done in my fork. I have manually tested auto-completion in bash and it works fine. I also ran the tests using run_test.py and they worked as well.

How do I go about getting the changes reviewed and then eventually make them to this repo to get this issue fixed?

@jayrajput
Copy link
Contributor

code is available for review. Please see the pull request.

@whimboo
Copy link
Contributor

whimboo commented Jun 13, 2014

Good to see that you picked that issue Jay! I will get to it soon. For now I will make you the assignee.

@whimboo
Copy link
Contributor

whimboo commented Jun 13, 2014

The referenced PR #221 was the mixture with another PR. So after talking to Jay he split out the code for this issue. So I will wait for the next PR you are opening.

@whimboo
Copy link
Contributor

whimboo commented Mar 11, 2015

An implementation here would be blocked by issue #269.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants