Line completion with custom commands

后端 未结 6 984
抹茶落季
抹茶落季 2020-12-23 17:33

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

$ myProgram doSomething
$ myProgram doSomethingElse
$ myProgram no         


        
6条回答
  •  醉梦人生
    2020-12-23 17:51

    There is the module optcomplete which allows you to write the completion for bash autocompletion in your python program. This is very useful in combination with optparse. You only define your arguments once, add the following to your .bashrc

    complete -F _optcomplete 
    

    and all your options will be autocompleted.

提交回复
热议问题