diff --git a/pubs/pubs b/pubs/pubs index 7699f18..68fd3d7 100755 --- a/pubs/pubs +++ b/pubs/pubs @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- +# PYTHON_ARGCOMPLETE_OK from pubs import pubs_cmd diff --git a/pubs/pubs_cmd.py b/pubs/pubs_cmd.py index 5b93893..62a58b8 100644 --- a/pubs/pubs_cmd.py +++ b/pubs/pubs_cmd.py @@ -7,6 +7,10 @@ from . import commands from . import update from . import plugins from .__init__ import __version__ +try: + import argcomplete +except ModuleNotFoundError: + argcomplete = None CORE_CMDS = collections.OrderedDict([ @@ -78,6 +82,8 @@ def execute(raw_args=sys.argv): for p in plugins.get_plugins().values(): p.update_parser(subparsers) + if argcomplete is not None: + argcomplete.autocomplete(parser) # Parse and run appropriate command args = parser.parse_args(remaining_args) args.prog = "pubs" # FIXME? diff --git a/readme.md b/readme.md index dfe19b4..960b6f3 100644 --- a/readme.md +++ b/readme.md @@ -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. +## 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 ? 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 - python >= 2.7 or >= 3.3 - +- [argcomplete](https://argcomplete.readthedocs.io) (optional, for autocompletion) ## Authors