Requests for Comments-11: Bash completion for command line OTB Applications

From OTBWiki
Jump to: navigation, search


  • Submitted by Guillaume Pasero (16/09/15 15:11)
  • Open for comments


What changes will be made and why they will make a better Orfeo ToolBox

The OTB Applications are a simple way to use the Orfeo Toolbox library. They offer at least 2 types of interface : a command line interface and a graphical interface. The command line interface requires to know the different keys to set the parameters (for instance : '-in' , '-out' , '-classifier.svm.type' ). This is displayed by the help message, but it would be very convenient to use bash completion to set the keys faster.

The bash completion doesn't impact the OTB library, it relies on external shell scripts, deployed usually in /etc/bash_completion.d (or a similar path). They impact the packaging of OTB. However, using the library to produce the completion scripts would be simple :

  • create an executable that loads each OTB application
  • for each application, get its keys
  • produce the completion script of this application in the build directory
  • optionnaly, when a choice parameter is detected, it is possible to use completion on the following token among the possible choice values (see example below)

I have made a small test for one application : Convert. The completion script is the following :

  local cur prev
  _get_comp_words_by_ref cur prev
  case "$cur" in
      key_list="-in -type -type.none -type.linear -type.log2 -type.linear.gamma -out -hcp -hcp.low -hcp.high -progress -ram -inxml"
      COMPREPLY=( $( compgen -W '$key_list' -- $cur) )
      return 0
  case "$prev" in
    key_list="none linear log2"
    COMPREPLY=( $( compgen -W '$key_list' -- $cur) )

  return 0

complete -o default -F _otbcli_Convert otbcli_Convert

'cur' is the current token to be guessed, 'prev' is the previous token.

I have tested this script successfully. Its generation can be automated without much efforts. It is also possible to use only one file to store the scripts for all the applications (to avoid flooding the bash_completion folder).

When will those changes be available (target release or date)

No planned release, but development effort is small.

Who will be developing the proposed changes?



  • The completion could also work with the following calls :
$ otbcli
$ otbcli  Convert

The first call would be completed with available applications. The second call would be completed with the application parameters. This usage of otbcli is a different feature though. See [1]

  • The completion could be made "dynamic" : calling otbcli in the completion script and parsing results. This could impact the performance as otbcli would actually load the application. See [2]
  • In the same spirit, patch for manpage proposed by Philippe should be integrated as well, since its purpose was to get completion from fish (friendly interactive shell). See [3]


This RFComments has received support from :

  • Julien Michel
  • Julien Malik
  • Conrad Bielski

Corresponding Requests for Changes