aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xosurl41
1 files changed, 16 insertions, 25 deletions
diff --git a/osurl b/osurl
index 34454db..2deb753 100755
--- a/osurl
+++ b/osurl
@@ -1,28 +1,19 @@
#!/usr/bin/luajit
-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"
-});
+local lpeg = require 'lpeg'
+local P,C,Cs,R = lpeg.P, lpeg.C, lpeg.Cs, lpeg.R
-print(pat:match("gh#python/cpython#123"))
-print(pat:match("lp#123456"))
-print(pat:match("bramboříček"))
+local cnum = C(R("09")^1)
+local cword = C(R("AZ","az","09","__")^1)
+local bugpat =
+ (P"bgo#" * cnum) / "http://bugzilla.gnome.org/show_bug.cgi?id=%1"
+ + (P"bko#" * cnum) / "http://bugzilla.kernel.org/show_bug.cgi?id=%1"
+ + (P"bmo#" * cnum) / "http://bugzilla.mozilla.org/show_bug.cgi?id=%1"
+ + (P"boo#" * cnum) / "http://bugzilla.opensuse.org/show_bug.cgi?id=%1"
+ + (P"bsc#" * cnum) / "http://bugzilla.suse.com/show_bug.cgi?id=%1"
+ + (P"gh#" * C((1 - P"#")^1) * P"#" * cword) / "https://github.com/%1/issues/%2"
+ + (P"lp#" * cnum) / "https://launchpad.net/bugs/%1"
+ + (P"rh#" * cnum) / "http://bugzilla.redhat.com/show_bug.cgi?id=%1"
+local pat = Cs((bugpat + P(1))^0)
+
+os.execute("xdg-open " .. pat:match(arg[1]))