Basic autocompletion with argcomplete.

Only support pubs command completion.
main
Olivier Mangin 8 years ago
parent 559d486236
commit af73d4ed64

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
# PYTHON_ARGCOMPLETE_OK
from pubs import pubs_cmd from pubs import pubs_cmd

@ -7,6 +7,10 @@ from . import commands
from . import update from . import update
from . import plugins from . import plugins
from .__init__ import __version__ from .__init__ import __version__
try:
import argcomplete
except ModuleNotFoundError:
argcomplete = None
CORE_CMDS = collections.OrderedDict([ CORE_CMDS = collections.OrderedDict([
@ -78,6 +82,8 @@ def execute(raw_args=sys.argv):
for p in plugins.get_plugins().values(): for p in plugins.get_plugins().values():
p.update_parser(subparsers) p.update_parser(subparsers)
if argcomplete is not None:
argcomplete.autocomplete(parser)
# Parse and run appropriate command # Parse and run appropriate command
args = parser.parse_args(remaining_args) args = parser.parse_args(remaining_args)
args.prog = "pubs" # FIXME? args.prog = "pubs" # FIXME?

@ -88,6 +88,13 @@ The first command defines a new subcommand: `pubs open -w evince` will be execut
The second starts with a bang: `!`, and is treated as a shell command. The second starts with a bang: `!`, and is treated as a shell command.
## Autocompletion
For autocompletion to work, you need the [argcomplete](https://argcomplete.readthedocs.io) python package.
For bash completion, just activate it globally with the command `activate-global-python-argcomplete`, or `activate-global-python-argcomplete --user`, that will copy `python-argcomplete.sh` to `/etc/bash_completion.d/` or `~/.bash_completion.d/`. You need to make sure that the file is evaluated on bash start. For more information or other shells please report to [argcomplete's documentation](https://argcomplete.readthedocs.io).
## Need more help ? ## Need more help ?
You can access the self-documented configuration by using `pubs conf`, and all the commands's help is available with the `--help` option. Did not find an answer to your question? Drop us an issue. We may not answer right away (science comes first!) but we'll eventually look into it. You can access the self-documented configuration by using `pubs conf`, and all the commands's help is available with the `--help` option. Did not find an answer to your question? Drop us an issue. We may not answer right away (science comes first!) but we'll eventually look into it.
@ -96,7 +103,7 @@ You can access the self-documented configuration by using `pubs conf`, and all t
## Requirements ## Requirements
- python >= 2.7 or >= 3.3 - python >= 2.7 or >= 3.3
- [argcomplete](https://argcomplete.readthedocs.io) (optional, for autocompletion)
## Authors ## Authors

Loading…
Cancel
Save