Giter Site home page Giter Site logo

oubiwann / optcomplete Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 188 KB

Shell Completion Self-Generator for Python

Home Page: https://bitbucket.org/blais/optcomplete

License: BSD 3-Clause "New" or "Revised" License

Python 90.38% Shell 2.59% HTML 6.80% CSS 0.22%

optcomplete's Introduction

=======================================================
optcomplete: Shell Completion Self-Generator for Python
=======================================================

.. contents:: Table of Contents

Description
===========

This Python module aims at providing almost automatically shell completion for
any Python program that already uses the ``optparse`` module.

Motivation
----------

This module aims at placing the shell completion routine and the option parsing
code in a single location: in the program itself.

The logic is that since a program already knows about its options, and in Python
we have a standard module to specify them programmatically since Python-2.3
(``optparse``), the program itself is in the best position to suggest
completions for an incomplete command-line to a shell that invokes it.

Traditionally, this has been done by writing shell-specific descriptions
*separate* from the programs themselves, such as the `Bash Programmable
Completion <http://freshmeat.net/projects/bashcompletion/>`_ project.  This
approach requires maintaining the shell completion functions up-to-date with the
programs.

During development of this proof-of-concept, we were interested in finding if
the programs could not describe their completion routines themselves, using the
well-specified completion protocol in bash.  Similar completion routines could
be easily written for other shells and we could extend this module to
them.

This code comes with support for automatic completions for Bash and Zsh.


Documentation
=============

``optcomplete`` consists of a simple module `optcomplete.py
<lib/python/optcomplete.py>`_ which you should install somewhere in your
PYTHONPATH.

To add simple support to a program which already uses ``optparse``, simply add
the following code after the optparse declarations, *before* calling the
``parse_args()`` function on your options parser::

    import optcomplete
    optcomplete.autocomplete(parser)

Optionally, you can pass a completer as a second argument (see module code).

You also need to `source a Bash function <etc/optcomplete.bash>`_ and then to
tell Bash to trigger optcomplete completion for the specific programs that use
it::

   complete -F _optcomplete <program>


More examples:

- `Examples --- sample example output <doc/sample-output.html>`_;
- `A note about conditionals <doc/conditional.html>`_;

- `Simple test program speaks for itself <bin/optcomplete-simple>`_;
- `Test program with subcommands <bin/optcomplete-commands>`_;

- `CHANGES <CHANGES>`_
- `TODO <TODO>`_


Download
========

A Mercurial repository can be found at:

  http://bitbucket.org/blais/optcomplete


Copyright and License
=====================

Copyright (C) 2001-2004  Martin Blais.  All Rights Reserved.

This code is distributed under the `BSD License <COPYING>`_.


Author
======

Martin Blais <[email protected]>

optcomplete's People

Contributors

blais avatar oubiwann avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.