Home Home > 2009 > 12 > 22
Sign up | Login

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

Archive for December 22nd, 2009

Quick tip: Novell Bugzilla and Klipper

December 22nd, 2009 by

Klipper from KDE has a set of predefined actions triggered by content of the clipboard. So when you have it enabled, it show up the popup menu with all available browsers when you copy the URL. In my job I open many bugs and the bug numbers have the well defined format bnc#number. So why don’t define automatic action triggered by this regular expression?

Because Klipper expects only oneliner as an action, I wrote the short bash script obug.sh which expects one argument with a bugzilla string.

#!/bin/bash

[ -z "${1}" ] && {
  echo "bug number required"
  exit 1
}

regex='^(bnc|bug)?#[0-9]+$'
[[ "${1}" =~ ${regex} ]] || {
  echo "${1} did not match ${regex}"
  exit 2
}

firefox https://bugzilla.novell.com/show_bug.cgi?id=${1#*#}

It’s obvious how it works – it checks if the argument exists and if matches the pattern and then opens a firefox (it’d be a xdg-open, but I use firefox for Novell Bugzilla). There should be only one strange expression – ${1#*#}. It is a Shell Parameter Expansion. This expression removes all characters from the beginning of the string including first #, so it convert bnc#1234 to 1234.

Then I defined a new action in Klipper triggered by ^(bnc|bug)?#[0-9]+$, which calls obug.sh %s, where %s is the content of clipboard.
Klipper config

And after that all I selected the bnc#1234 by mouse and then the following popup appeared.

One disadvantage of this method is that Klipper opens popup window only near its status icon in systemtray. It would be more useful to show it near current mouse position.