Home Home > 2009 > 02 > 12 > Zypper: Improved bash completion and practical usage
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

Zypper: Improved bash completion and practical usage

February 12th, 2009 by

Because no one reported any bugs to perl-Bootloader, I have some free time. I use it to improve bash completion for zypper, because I find current one have some really annoying things. In short now completion work also for zypper global options, hint also for short version of commands and help name of repo, service and lock, if you use command which takes that as argument. Next few paragraphs contain practical examples how it help improve your command line productivity, how to get it to your system and also some notes how I implement it.
At first how you can try it. It is really easy, in 11.2 it will be part of package, 11.1 contain only old bash-completion (created by Marek Stopka), so you must download this file and save it as /etc/bash_completion.d/zypper.sh. After bash restart (simple type ‘bash’ to get new shell) you can enjoy new bash completion.
First change is that automatic hints works for all commands – long or short version and also on different zypper version (it is dynamic generated), so if you are not what is exactly name of option just use tab.

zofie:/home/jreidinger # zypper in --
--auto-agree-with-licenses --from
--capability --name
--debug-solver --no-force-resolution
--dry-run --no-recommends
--force --repo
--force-resolution --type

Improvement is also that it work also after first option (before it hint only first option after command. Now it also help you with global zypper option, so if you don’t yet write command you can type — and get all global options.

zofie:/home/jreidinger # zypper --
--cache-dir --plus-repo
--disable-repositories --quiet
--disable-system-resolvables --raw-cache-dir
--help --reposd-dir
--no-abbrev --root
--no-cd --rug-compatible
--no-gpg-checks --table-style
--non-interactive --verbose
--no-refresh --version
--no-remote --xmlout

What I find quite useful is that now you get hint also for repository, service or lock. I have quite long repository names and it is really annoying write it. So I usually use zypper lr to get number and then use that number instead repository name, as it is less typing. Now you can get help (problem is with names with spaces, I reported it):

zofie:/home/jreidinger # zypper ref repo-
repo-debug repo-non-oss repo-oss repo-source repo-update

So I hope you enjoy this improvements and I welcome any idea how improve it in comments.
Last paragraph is some notes about implementation. At first for compare you can look at original bash complete from marek stopka here. First what you can see, is that I remove static generating options help and create it dynamic. This really improve maintenance of this script. Only part which is static is special command handling like commands with repository, service or lock arguments. Second change is that now commands is recognized also if user use short option (e.g. when user type zypper mr and want hint for repository). This is quite easy change, as I only change awk output and remove comma between long and short version of command. Next change is more backward study of user line to find what command is typed. As you can see in original is study only previous argument. This causes problem when user want more options or use option and want help for argument. After my rewrite script is shorted by 20% and has better functionality and maintainability.

Both comments and pings are currently closed.

9 Responses to “Zypper: Improved bash completion and practical usage”

  1. Anonymous

    hm, i´d appreciate improving to remove orphaned packages

  2. apokryphos

    Nice improvements, using them now, thanks!

  3. Jagg

    Nice… thanks!

    (your “file”-link is wrong, http://http//git.opens..... )

  4. Exciting news. I like this kind of progress. Let’s just hope that it is working as it should when 11.2 comes out.

    • Josef Reidinger

      You can try some testing release of 11.2 and try it, if it works as you expect. I can improve it during testing phase, but cannot after release.

  5. Marcel Witte

    Nice feature!
    This is one feature I bedrugde ubuntu-users about (aptitude still has it, even for package-names)

    But it isn’t working with sudo before zypper
    Also it doesn’t work in shell-mode (“zypper sh”)