Line completion with custom commands

后端 未结 6 1016
抹茶落季
抹茶落季 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:38

    As mentioned in other answers, in bash this can be done with the bash-builtin complete. Easier than writing a function (as in richq's answer) is using complete's option -W which lets you specify a list of words. In your example this would be:

    complete -W "doSomething doSomethingElse nowDoSomethingDifferent" myProgram
    

    As it is a one-liner you don't have to create a file for this, but you can just put it in your .bashrc.

提交回复
热议问题