Line completion with custom commands

Discussion in 'Python' started by gu, Jan 9, 2009.

  1. gu

    gu Guest

    Hi, my Python program can be launched with a range of different options
    (or subcommands) like:

    $ myProgram doSomething
    $ myProgram doSomethingElse
    $ myProgram nowDoSomethingDifferent

    I want it to use auto-completion with so that if i type "myProgram d" it
    returns "myProgram doSomething" and if i type "myProgram n" it renders
    "myProgram nowDoSomethingDifferent". This is similar to the average use
    of the module rlcompleter, but it does not pick possible completion
    options from the filesystem (or from history) but from a custom set of
    strings (that correspond to the available options for my program)

    Any idea on how to implement this?

    I'm aware of the variable PYTHONSTARTUP (that should point to a file I
    don't know how to write).

    As a working example, django-admin (from the django package) has the
    same exact feature i'm looking for
     
    gu, Jan 9, 2009
    #1
    1. Advertising

  2. gu

    Steve Holden Guest

    gu wrote:
    >
    > Hi, my Python program can be launched with a range of different options
    > (or subcommands) like:
    >
    > $ myProgram doSomething
    > $ myProgram doSomethingElse
    > $ myProgram nowDoSomethingDifferent
    >
    > I want it to use auto-completion with so that if i type "myProgram d" it
    > returns "myProgram doSomething" and if i type "myProgram n" it renders
    > "myProgram nowDoSomethingDifferent". This is similar to the average use
    > of the module rlcompleter, but it does not pick possible completion
    > options from the filesystem (or from history) but from a custom set of
    > strings (that correspond to the available options for my program)
    >
    > Any idea on how to implement this?
    >
    > I'm aware of the variable PYTHONSTARTUP (that should point to a file I
    > don't know how to write).
    >
    > As a working example, django-admin (from the django package) has the
    > same exact feature i'm looking for


    The issue here is that Python doesn't get control until afer you've hit
    RETURN on the command line. so nothing you can do in your program or
    interpreter setup will have any effect on how the command shell behaves.

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Jan 9, 2009
    #2
    1. Advertising

  3. gu

    gu Guest

    Steve Holden wrote:
    > gu wrote:
    >> Hi, my Python program can be launched with a range of different options
    >> (or subcommands) like:
    >>
    >> $ myProgram doSomething
    >> $ myProgram doSomethingElse
    >> $ myProgram nowDoSomethingDifferent
    >>
    >> I want it to use auto-completion with so that if i type "myProgram d" it
    >> returns "myProgram doSomething" and if i type "myProgram n" it renders
    >> "myProgram nowDoSomethingDifferent". This is similar to the average use
    >> of the module rlcompleter, but it does not pick possible completion
    >> options from the filesystem (or from history) but from a custom set of
    >> strings (that correspond to the available options for my program)
    >>
    >> Any idea on how to implement this?
    >>
    >> I'm aware of the variable PYTHONSTARTUP (that should point to a file I
    >> don't know how to write).
    >>
    >> As a working example, django-admin (from the django package) has the
    >> same exact feature i'm looking for

    >
    > The issue here is that Python doesn't get control until afer you've hit
    > RETURN on the command line. so nothing you can do in your program or
    > interpreter setup will have any effect on how the command shell behaves.
    >
    > regards
    > Steve


    I see, but how does django-admin work, then?
     
    gu, Jan 9, 2009
    #3
  4. gu

    gu Guest

    Steve Holden wrote:
    > gu wrote:
    >> Hi, my Python program can be launched with a range of different options
    >> (or subcommands) like:
    >>
    >> $ myProgram doSomething
    >> $ myProgram doSomethingElse
    >> $ myProgram nowDoSomethingDifferent
    >>
    >> I want it to use auto-completion with so that if i type "myProgram d" it
    >> returns "myProgram doSomething" and if i type "myProgram n" it renders
    >> "myProgram nowDoSomethingDifferent". This is similar to the average use
    >> of the module rlcompleter, but it does not pick possible completion
    >> options from the filesystem (or from history) but from a custom set of
    >> strings (that correspond to the available options for my program)
    >>
    >> Any idea on how to implement this?
    >>
    >> I'm aware of the variable PYTHONSTARTUP (that should point to a file I
    >> don't know how to write).
    >>
    >> As a working example, django-admin (from the django package) has the
    >> same exact feature i'm looking for

    >
    > The issue here is that Python doesn't get control until afer you've hit
    > RETURN on the command line. so nothing you can do in your program or
    > interpreter setup will have any effect on how the command shell behaves.
    >
    > regards
    > Steve


    I see, but how does django-admin work, then?
     
    gu, Jan 9, 2009
    #4
  5. gu wrote:

    > I see, but how does django-admin work, then?


    from bash:

    complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram
     
    Marco Mariani, Jan 9, 2009
    #5
  6. gu

    Steve Holden Guest

    gu wrote:
    > Steve Holden wrote:
    >> gu wrote:
    >>> Hi, my Python program can be launched with a range of different options
    >>> (or subcommands) like:
    >>>
    >>> $ myProgram doSomething
    >>> $ myProgram doSomethingElse
    >>> $ myProgram nowDoSomethingDifferent
    >>>
    >>> I want it to use auto-completion with so that if i type "myProgram d" it
    >>> returns "myProgram doSomething" and if i type "myProgram n" it renders
    >>> "myProgram nowDoSomethingDifferent". This is similar to the average use
    >>> of the module rlcompleter, but it does not pick possible completion
    >>> options from the filesystem (or from history) but from a custom set of
    >>> strings (that correspond to the available options for my program)
    >>>
    >>> Any idea on how to implement this?
    >>>
    >>> I'm aware of the variable PYTHONSTARTUP (that should point to a file I
    >>> don't know how to write).
    >>>
    >>> As a working example, django-admin (from the django package) has the
    >>> same exact feature i'm looking for

    >>
    >> The issue here is that Python doesn't get control until afer you've hit
    >> RETURN on the command line. so nothing you can do in your program or
    >> interpreter setup will have any effect on how the command shell behaves.
    >>
    >> regards
    >> Steve

    >
    > I see, but how does django-admin work, then?
    >

    Probably the issue you has was not knowing the name of the feature. When
    I asked Google to tell me about django-admin command completion it said:

    http://code.djangoproject.com/ticket/1240

    as the first hit. As you will see, this is done by configuring the shell
    to know about the specific commands it has to deal with. Enjoy!

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
     
    Steve Holden, Jan 9, 2009
    #6
  7. gu

    gu Guest

    Marco Mariani wrote:
    > gu wrote:
    >
    >> I see, but how does django-admin work, then?

    >
    > from bash:
    >
    > complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram


    This worked like a charm, thank you so much. Is this available for bash
    only or any shell?
     
    gu, Jan 9, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    4,009
    Thomas Stegen
    Jun 28, 2003
  2. Tim Stanka
    Replies:
    1
    Views:
    836
    Jeff Epler
    Aug 2, 2004
  3. ntwrkd
    Replies:
    0
    Views:
    322
    ntwrkd
    May 22, 2010
  4. ziggs
    Replies:
    2
    Views:
    205
    Henry Robinson
    Apr 21, 2004
  5. Bill Atkins
    Replies:
    6
    Views:
    145
    Dave Baldwin
    Aug 11, 2005
Loading...

Share This Page