Line completion with custom commands

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

    Create a file "myprog-completion.bash" and source it in your .bashrc file. Something like this to get you started...

    _myProgram()
    {
      cur=${COMP_WORDS[COMP_CWORD]}
      case "${cur}" in
        d*) use="doSomething" ;;
        n*) use="nowDoSomethingElse" ;;
      esac
      COMPREPLY=( $( compgen -W "$use" -- $cur ) )
    }
    complete -o default -o nospace -F _myProgram  myProgram
    

提交回复
热议问题