29 Mar 2010 00:13 Subscribe

z-shell (zsh) completion for osc and zypper

When working with the openSUSE distribution, there are a couple of tools you have to deal with over and over again. Two of them are osc and zypper. The first one to build or fix packages, the latter to install, remove or update them. Using one of those tools on a regular basis? Read on…

…but to make this post actually useful for you, there needs to be another prerequisite: You need to use zsh as your primary shell. And I hope you do. If not, you should definitely put this on your TODO list.

All of the following is ready to use, because it's already in openSUSE Factory for quite some time and has already been in openSUSE 11.2. I just have the feeling that people are not aware of this feature, so I am writing this post…

osc

So let's start with osc. There are a couple of sub commands like checkout, getbinaries or branch I need all the time. And every time I do, I have to look up the syntax. For instance, have a look at the osc getbinaries command:

$ osc help getbinaries
osc getbinaries PROJECT PACKAGE REPOSITORY ARCHITECTURE

Hm? Four parameters? Things like that were actually the reason I sat down implementing a solution which works quite well for me: Zsh completion for osc. Now you can do stuff like the following:

$ osc getbinaries <tab>
home:hmacht              openSUSE:11.0            openSUSE:11.3            SUSE:SLE-11:Update:Test
home:hmacht:kernel-sony  openSUSE:11.1            openSUSE:Factory
openSUSE:10.3            openSUSE:11.2            SUSE:SLE-11-SP1:GA

$ osc getbinaries openSUSE:Factory aaa_base <tab>
openSUSE_10.2     openSUSE_11.0     openSUSE_11.2     openSUSE_Factory  SUSE_SLE-11_GA
openSUSE_10.3     openSUSE_11.1     openSUSE_11.3     standard

$ osc getbinaries openSUSE:Factory aaa_base openSUSE_Factory
i586    x86_64

Quite handy, isn't it?

You might also wonder why the first completion output in the above example contains my personal home project home:hmacht. By default, the completion contains a couple of default build targets, repositories and architectures like openSUSE_Factory, openSUSE:Factory or x86_64. You can extend those lists with the shell variables ZSH_OSC_PROJECTS_EXTRA and ZSH_OSC_BUILD_TARGETS_EXTRA. My corresponding part of my ~/.zshrc looks so:

export ZSH_OSC_PROJECTS_EXTRA="home:hmacht home:hmacht:kernel-sony SUSE:SLE-11:Update:Test SUSE:SLE-11-SP1:GA"
export ZSH_OSC_BUILD_TARGETS_EXTRA="standard SUSE_SLE-11_GA"

After that, the extra repos/targets show up in the completion output.

By default, the completion is in verbose mode:

$ osc <tab>
--debugger             -- jump into the debugger before executing anything
--no-keyring           -- disable usage of desktop keyring system
--post-mortem          -- jump into the debugger in case of errors
--version              -- show program's version number and exit
-A                     -- URL/alias, --apiurl=URL/alias
-H                     -- --http-debug debug HTTP traffic
-c                     -- FILE, --config=FILE
-d                     -- --debug print info useful for debugging
-h                     -- --help show this help message and exit
-q                     -- --quiet be quiet, not verbose
-t                     -- --traceback print call trace in case of errors
-v                     -- --verbose increase verbosity
abortbuild             -- Aborts the build of a certain project/package
add                    -- Mark files to be added upon the next commit
addremove              -- (ar) Adds new files, removes disappeared files
aggregatepac           -- "Aggregate" a package to another package
api                    -- Issue an arbitrary request to the API
branch                 -- (bco, branchco, getpac)
bugowner               -- Show bugowners of a project/package
build                  -- Build a package on your local machine
[...]

To change that you can set

$ zstyle ':completion:*:osc:*' verbose no
$ zstyle ':completion:*:osc-subcommand:*' verbose no

Now it looks like:

$ osc <tab>
--debugger             api                    diff                   meta                   resolved
--no-keyring           branch                 disable                mkpac                  results
--post-mortem          bugowner               getbinaries            mv                     rremove
--version              build                  global                 my                     search
[...]

All the completion output is auto generated by the osc help output (btw., even osc help <tab> can be completed), so new commands should show up automatically. However, this contains the risk of possible bugs where the help output is unexpected, so if you find any issues, send me a mail or add a comment.

zypper

Basically all the above applies for zypper. An example output looks like:

$ zypper re<tab>
refresh                 -- ref Refresh all repositories.
refresh-services        -- refs Refresh all services.
remove                  -- rm Remove packages.
removelock              -- rl Remove a package lock.
removerepo              -- rr Remove specified repository.
removeservice           -- rs Remove specified service.
renamerepo              -- nr Rename specified repository.
repos                   -- lr List all defined repositories.

Change verbose/short output with:

$ zstyle ':completion:*:osc:*' verbose no
$ zstyle ':completion:*:osc-subcommand:*' verbose no

Personally I use the zypper completion quite seldom, nevertheless, some people might find it useful.

 


blog comments powered by Disqus