diff options
-rwxr-xr-x | osurl | 49 |
1 files changed, 26 insertions, 23 deletions
@@ -1,25 +1,28 @@ -#!/usr/bin/lua +#!/usr/bin/luajit -local function expAbbr(instr) - local patterns = { - ["bgo#(%d+)"]="http://bugzilla.gnome.org/show_bug.cgi?id=%1", - ["bko#(%d+)"]="http://bugzilla.kernel.org/show_bug.cgi?id=%1", - ["bmo#(%d+)"]="http://bugzilla.mozilla.org/show_bug.cgi?id=%1", - ["boo#(%d+)"]="http://bugzilla.opensuse.org/show_bug.cgi?id=%1", - ["bsc#(%d+)"]="http://bugzilla.suse.com/show_bug.cgi?id=%1", - ["bnc#(%d+)"]="http://bugzilla.novell.com/show_bug.cgi?id=%1", - ["gh#([^#]+)#(%w+)"]="https://github.com/%1/issues/%2", - ["lp#(%d+)"]="https://launchpad.net/bugs/%1", - ["rh#(%d+)"]="http://bugzilla.redhat.com/show_bug.cgi?id=%1", - } +local re = require 're' +local pat = re.compile([[ + str <- {~ (bug / .)* ~} !. + num <- { %d+ } + bug <- (("bgo#" num) -> BGO) + / (("bko#" num) -> BKO) + / (("bmo#" num) -> BMO) + / (("boo#" num) -> BOO) + / (("bsc#" num) -> BSC) + / (("gh#" { (!"#" .)+ } "#" { %w+ }) -> GH) + / (("lp#" num) -> LP) + / (("rh#" num) -> RH) +]],{ + BGO = "http://bugzilla.gnome.org/show_bug.cgi?id=%1", + BKO = "http://bugzilla.kernel.org/show_bug.cgi?id=%1", + BMO = "http://bugzilla.mozilla.org/show_bug.cgi?id=%1", + BOO = "http://bugzilla.opensuse.org/show_bug.cgi?id=%1", + BSC = "http://bugzilla.suse.com/show_bug.cgi?id=%1", + GH = "https://github.com/%1/issues/%2", + LP = "https://launchpad.net/bugs/%1", + RH = "http://bugzilla.redhat.com/show_bug.cgi?id=%1" +}); - for pat, repl in pairs(patterns) do - local newurl, res = string.gsub(instr, pat, repl) - if res == 1 then - return newurl - end - end - return instr -end - -os.execute("xdg-open " .. expAbbr(arg[1])) +print(pat:match("gh#python/cpython#123")) +print(pat:match("lp#123456")) +print(pat:match("bramboříček")) |