1

Possible Duplicate:
Python argparse and bash completion

In a bash prompt (like on a Ubuntu system) if you type service and then tab a few times you would get a list of all the services available.

Is there a way to do the same with a python script? So if you had a script called music that looked like this:

def dumbstuff():
    #plays pop music...

def rockingstuff():
    #Plays music that will scare your mother...

And on the command line you type music with a few tabs I would like to see outputted:

dumbstuff
rockingstuff

Is there a way to do this?

Community
  • 1
  • 1
beeryardtech
  • 605
  • 1
  • 4
  • 15

1 Answers1

1

You could go about this two way. The first methodology would be to create a bash completion script and reference it in your .bashrc file. You can see and example of this here:An Introduction to Programmable Completion.

The other way you could go is to use the optcomplete library for python. You have to include it as part of your script.

Which methodology you choose depends on whether this application is just for personal use or distribution.

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
BigHandsome
  • 4,843
  • 5
  • 23
  • 30