Home Home > 2010 > 06 > 15 > Hackweek V: osc bash completion
Sign up | Login

Hackweek V: osc bash completion

June 15th, 2010 by

During last week , I was working on my Hackweek V project: bash completion for osc. It’s still far from being complete, but IMHO it is usable already, so here we go.


The project is hosted on gitorious.org. To get the sources, use git:

git clone git://gitorious.org/opensuse/osc-bash-completion.git


You need working and configured osc. I have tested the completion with osc-0.126git, but it should more or less work with older/newer versions too. Naturally, your shell has to be bash (I used bash-4.x). The easiest way how to try the completion is simply to do
~> source osc.shThis will enable the completion for the given shell only – see README for more “persistent” ways how to enable the osc completion.


The script provides support for completing:

  • osc subcommand names (checkout, commit, …)
  • global long osc options (e.g. –quiet, –debug, …)
  • long subcommand options
  • project names
  • package names (in given project)
  • file names (in given project/package)
  • repository names (openSUSE_Factory, …)
  • architectures (i586, x86_64, …)

Some examples:
osc com<tab><tab> => osc commit
osc --ht<tab><tab> => osc --http-debug
osc build --a<tab><tab> => osc build --alternative-project
osc ls Ar<tab><tab> => osc ls Archiving
osc ls Base:System pa<tab><tab> => osc ls Base:System parted
osc cat Base:System parted ba<tab><tab> => osc cat Base:System parted baselibs.conf
osc buildlog openSUSE_<tab><tab> => osc buildlog openSUSE_
openSUSE_Factory openSUSE_11.0 openSUSE_11.1 openSUSE_11.2

osc buildlog openSUSE_Factory x<tab><tab> => osc buildlog openSUSE_Factory x86_64
osc createrequest -a<tab><tab> => osc createrequest -a
add_role delete change_devel set_bugowner submit

osc ? d<tab><tab> => osc ?
delete deleterequest dependson dif

osc meta a<tab><tab> => osc meta attribute
osc my <tab><tab> => osc my
pkg prj rq sr

osc request <tab><tab> => osc request
accept approvenew co decline checkout
list log revoke show wipe

osc getpac for<tab><tab> => osc gepac fortune

At the moment, the script DOES NOT provide support for completing

  • short options
  • arguments for most of the options
  • some complex combinations of arguments


To avoid long delays and spamming OBS server too much, the script caches several information:

  • list of projects in OBS
  • list of packages in individual projects (only in those that have been accessed by osc)
  • output of “osc repos prj” (dtto)

Please see the README file for more information about how the caching works and how to customize it (to make the completion significantly faster).

Known issues, TODO

  • The script does not work correctly if there is a long option with argument and there is ‘=’ between the option and argument (–long-option=arg). Please use the ‘–long-option arg’ form instead.
  • For the time being, the script does not recognize alternative apiurl (-A|–apiurl) and thus it works only with default (https://api.opensuse.org) api.
  • Sourcing the script removes the colon from COMP_WORDBREAKS variable to make completion of Build Service projects easier. This was known to break e.g. git completion in the past (however, I didn’t notice any issues). In the future, the script should be fixed so that modifying of COMP_WORDBREAKS is not necessary.
  • The script should dynamically create list of osc subcommands and lists of their options by parsing osc help output (or something similar). Now the lists and logic are hardcoded in the script, which will make it maintenance nightmare when osc changes.
  • Completing of “osc {chroot,build}” is not yet implemented.
  • See TODO file

Testing and feedback

The completion script is very new, tested only by me and mvyskocil for a while, so it definitely has a lot of bugs. Before releasing it as a separate package, I’d like to collect some feedback first (and fix the already known problems and TODOs), so, if you are interested, please give it a try and report any bugs, suggestions or patches directly to me (petr.uzel@suse.cz). Also, feel free to ping me on IRC: ptr_uzl @ freenode.net.

I hope at least somebody (except me :) ) will find the completion useful. Thanks and happy completing.

Both comments and pings are currently closed.

4 Responses to “Hackweek V: osc bash completion”

  1. Josef Reidinger

    Nice. I find completion quite useful. I think that you can see for inspiration zypper completion which uses dynamic parsing of options.

  2. Lars

    For the caching of projects: what about querying the “Watchlist” of a user? (osc meta user )

    Can you make this configurable – so users do not need to see _all_ the projects, but just the ones their have in their watchlist?

  3. Petr Uzel

    Thanks for the hint – I’ll definitely have a look into zypper completion.

  4. Petr Uzel

    Lars, good idea – thank you. I hope I’ll find some free time to improve the completion script soon.