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.
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.
Both comments and pings are currently closed.
Here’s the same in one line:
xdg-open exec https://bugzilla.novell.com/show_bug.cgi?id=`echo %s| sed 's/bnc.*#//g'`
Correction:
xdg-open https://bugzilla.novell.com/show_bug.cgi?id=`echo %s| sed ‘s/bnc.*#//g’`
is correct – xdg-open doesn’t take ‘exec’ as an argument, were you thinking of kioclient or kfmclient?
It would be more useful to show it near current mouse position.
The very first option in Klipper Settings will we a pleasant surprise for you 🙂