From 04d43ecce25fa982392e08591b7cf055138aea11 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 16 Oct 2023 14:52:24 +0200 Subject: fix(osurl): port osurl to POSIX shell script. --- osurl | 159 +++++++++++++++++++++++++----------------------------------------- 1 file changed, 60 insertions(+), 99 deletions(-) (limited to 'osurl') diff --git a/osurl b/osurl index 12a40aa..7a96400 100755 --- a/osurl +++ b/osurl @@ -1,99 +1,60 @@ -#!/usr/bin/lua --- Expand abbreviations from --- https://en.opensuse.org/openSUSE:Packaging_Patches_guidelines#Current_set_of_abbreviations - -local lpeg = require 'lpeg' -local P,C,Cs,Cf,R,S = lpeg.P, lpeg.C, lpeg.Cs, lpeg.Cf, lpeg.R, lpeg.S - -local tokens = { - NONHASH = C((1 - S("#!@"))^1), -- any nonempty string not containing # - AT = S("@"), -- @ separator - DOL = S("!"), -- ! separator - SEP = S("#-"), -- separators, can be # or - - NUM = C(R("09")^1), -- nonempty digit string - WORD = C(R("AZ","az","09","__")^1), -- nonempty word - JIRID = C(R("AZ","az","09","--")^1) -- nonempty word -} -local patterns = { - ["bgo%SEP%NUM"] = "https://bugzilla.gnome.org/show_bug.cgi?id=%1", - ["bpo%SEP%NUM"] = "https://bugs.python.org/issue%1", - ["bko%SEP%NUM"] = "https://bugzilla.kernel.org/show_bug.cgi?id=%1", - ["bmo%SEP%NUM"] = "https://bugzilla.mozilla.org/show_bug.cgi?id=%1", - ["boo%SEP%NUM"] = "https://bugzilla.opensuse.org/show_bug.cgi?id=%1", - ["bnc%SEP%NUM"] = "https://bugzilla.novell.com/show_bug.cgi?id=%1", - ["bsc%SEP%NUM"] = "https://bugzilla.suse.com/show_bug.cgi?id=%1", - ["bds%SEP%NUM"] = "https://build.suse.de/request/show/%1", - ["isr%SEP%NUM"] = "https://build.suse.de/request/show/%1", - ["ssr%SEP%NUM"] = "https://build.suse.de/request/show/%1", - ["bdo%SEP%NUM"] = "https://build.opensuse.org/request/show/%1", - ["sr%SEP%NUM"] = "https://build.opensuse.org/request/show/%1", - ["jsc%SEP%JIRID"] = "https://jira.suse.com/browse/%1", - ["gh%SEP%NONHASH%SEP%WORD"] = "https://github.com/%1/issues/%2", - ["gh%SEP%NONHASH%AT%WORD"] = "https://github.com/%1/commit/%2", - ["gh%SEP%NONHASH%DOL%WORD"] = "https://github.com/%1/discussions/%2", - ["gl%SEP%NONHASH%SEP%WORD"] = "https://gitlab.com/%1/issues/%2", - ["gl%SEP%NONHASH%DOL%WORD"] = "https://gitlab.com/%1/-/merge_requests/%2", - ["bt%SEP%NONHASH%SEP%WORD"] = "https://bitbucket.org/%1/issues/%2", - ["sh%SEP%NUM"] = "http://sourceforge.net/support/tracker.php?aid=%1", - ["shb%SEP%NONHASH%SEP%NUM"] = "https://sourceforge.net/p/%1/bugs/%2/", - ["shp%SEP%NONHASH%SEP%NUM"] = "https://sourceforge.net/p/%1/patches/%2/", - ["sht%SEP%NONHASH%SEP%NUM"] = "https://sourceforge.net/p/%1/tickets/%2/", - ["lp%SEP%NUM"] = "https://launchpad.net/bugs/%1", - ["rh%SEP%NUM"] = "https://bugzilla.redhat.com/show_bug.cgi?id=%1", - ["rhbz%SEP%NUM"] = "https://bugzilla.redhat.com/show_bug.cgi?id=%1", - ["tdf%SEP%NUM"] = "https://bugs.documentfoundation.org/show_bug.cgi?id=%1", - ["pep%SEP%NUM"] = "https://www.python.org/dev/peps/pep-%1", - ["ffn%SEP%NUM"] = "https://www.fanfiction.net/s/%1", - ["ao3%SEP%NUM"] = "https://archiveofourown.org/works/%1", - ["boost%SEP%NUM"] = "https://svn.boost.org/trac/boost/%1", - ["RT%SEP%NUM"] = "https://rt.cpan.org/Public/%1", - ["deb%SEP%NUM"] = "https://bugs.debian.org/%1", - ["fdo%SEP%NUM"] = "https://bugs.freedesktop.org/%1", - ["glfo%SEP%NONHASH%SEP%NUM"] = "https://gitlab.freedesktop.org/%1/issues/%2", - ["gcc%SEP%NUM"] = "https://gcc.gnu.org/bugzilla/%1", - ["glgo%SEP%NONHASH%SEP%NUM"] = "https://gitlab.gnome.org/%1/issues/%2", - ["kde%SEP%NUM"] = "https://bugs.kde.org/%1", - ["obs%SEP%NUM"] = "https://api.github.com/repos/openSUSE/open-build-service/issues/%1", - ["build%SEP%NUM"] = "https://api.github.com/repos/openSUSE/obs-build/issues/%1", - ["osc%SEP%NUM"] = "https://api.github.com/repos/openSUSE/osc/issues/%1", - ["poo%SEP%NUM"] = "https://progress.opensuse.org/issues/%1", - ["lf%SEP%NUM"] = "https://developerbugs.linux-foundation.org/%1", - ["coo%SEP%NONHASH%SEP%NUM"] = "https://code.opensuse.org/%1/issue/%2", - ["code-o-o%SEP%NONHASH%SEP%NUM"] = "https://code.opensuse.org/%1/issue/%2", -} - - --- turn "foo#%BLAH" into a pattern that matches everything literally except --- %BLAH -local makepat = Cf( - ( - ((P("%") * C(R("AZ")^1)) / tokens) -- %BLAH is from tokens - + (P"%%" / function() return P"%" end) -- %% treat as literal % - + (C(P(1)) / P) -- anything else is literal - )^0, - function(a,b) return a * b end) -local function make_pattern(str) - return assert(makepat:match(str), "invalid pattern") -end - -local bugpat = P(false) -for k,v in pairs(patterns) do - bugpat = bugpat + (make_pattern(k) / v) -end -local pat = Cs((bugpat + P(1))^0) - -local in_url = arg[1] --- print("in_url = " .. in_url) -local out_url = pat:match(in_url:lower()) --- print("out_url = " .. out_url) -if out_url == in_url:lower() then - out_url = in_url -end --- print("out_url = " .. out_url) - -local open_util = "xdg-open " -if os.execute('type flatpak-xdg-open >/dev/null 2>/dev/null') then - open_util = "flatpak-xdg-open " -end - -os.execute(open_util .. out_url) +#!/bin/sh +# Expand abbreviations from +# https://en.opensuse.org/openSUSE:Packaging_Patches_guidelines#Current_set_of_abbreviations +set -eu + +if [ $# -le 1 ] ; then +STR="$(cat)" +else +STR="$1" +fi + +STR="$(echo "$STR" | sed -E -e 's@bgo[#-]([0-9])@https://bugzilla.gnome.org/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@bpo[#-]([0-9])@https://bugs.python.org/issue\1@')" +STR="$(echo "$STR" | sed -E -e 's@bko[#-]([0-9])@https://bugzilla.kernel.org/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@bmo[#-]([0-9])@https://bugzilla.mozilla.org/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@boo[#-]([0-9])@https://bugzilla.opensuse.org/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@bnc[#-]([0-9])@https://bugzilla.novell.com/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@bsc[#-]([0-9])@https://bugzilla.suse.com/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@bds[#-]([0-9])@https://build.suse.de/request/show/\1@')" +STR="$(echo "$STR" | sed -E -e 's@isr[#-]([0-9])@https://build.suse.de/request/show/\1@')" +STR="$(echo "$STR" | sed -E -e 's@ssr[#-]([0-9])@https://build.suse.de/request/show/\1@')" +STR="$(echo "$STR" | sed -E -e 's@bdo[#-]([0-9])@https://build.opensuse.org/request/show/\1@')" +STR="$(echo "$STR" | sed -E -e 's@sr[#-]([0-9])@https://build.opensuse.org/request/show/\1@')" +STR="$(echo "$STR" | sed -E -e 's@jsc[#-](\S+)@https://jira.suse.com/browse/\1@')" +STR="$(echo "$STR" | sed -E -e 's@gh[#-]([^#]*)[#-]([0-9]+)@https://github.com/\1/issues/\2@')" +STR="$(echo "$STR" | sed -E -e 's!gh[#-]([^#]*)@(\S+)!https://github.com/\1/commit/\2!')" +STR="$(echo "$STR" | sed -E -e 's@gh[#-]([^#]*)!(\S+)@https://github.com/\1/discussions/\2@')" +STR="$(echo "$STR" | sed -E -e 's@gl[#-]([^#]*)[#-](\S+)@https://gitlab.com/\1/issues/\2@')" +STR="$(echo "$STR" | sed -E -e 's@gl[#-]([^#]*)!(\S+)@https://gitlab.com/\1/-/merge_requests/\2@')" +STR="$(echo "$STR" | sed -E -e 's@bt[#-]([^#]*)[#-](\S+)@https://bitbucket.org/\1/issues/\2@')" +STR="$(echo "$STR" | sed -E -e 's@glfo[#-]([^#]*)[#-](\S+)@https://gitlab.freedesktop.org/\1/issues/\2@')" +STR="$(echo "$STR" | sed -E -e 's@glgo[#-]([^#]*)[#-](\S+)@https://gitlab.gnome.org/\1/issues/\2@')" +STR="$(echo "$STR" | sed -E -e 's@coo[#-]([^#]*)[#-](\S+)@https://code.opensuse.org/\1/issue/\2@')" +STR="$(echo "$STR" | sed -E -e 's@code-o-o[#-]([^#]*)[#-](\S+)@https://code.opensuse.org/\1/issue/\2@')" +STR="$(echo "$STR" | sed -E -e 's@sh[#-]([0-9]+)@http://sourceforge.net/support/tracker.php?aid=\1@')" +STR="$(echo "$STR" | sed -E -e 's@shb[#-](.*)[#-]([0-9]+)@https://sourceforge.net/p/\1/bugs/\2/@')" +STR="$(echo "$STR" | sed -E -e 's@shp[#-](.*)[#-]([0-9]+)@https://sourceforge.net/p/\1/patches/\2/@')" +STR="$(echo "$STR" | sed -E -e 's@sht[#-](.*)[#-]([0-9]+)@https://sourceforge.net/p/\1/tickets/\2/@')" +STR="$(echo "$STR" | sed -E -e 's@lp[#-]([0-9]+)@https://launchpad.net/bugs/\1@')" +STR="$(echo "$STR" | sed -E -e 's@rh[#-]([0-9]+)@https://bugzilla.redhat.com/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@rhbz[#-]([0-9]+)@https://bugzilla.redhat.com/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@tdf[#-]([0-9]+)@https://bugs.documentfoundation.org/show_bug.cgi?id=\1@')" +STR="$(echo "$STR" | sed -E -e 's@pep[#-]([0-9]+)@https://www.python.org/dev/peps/pep-\1@')" +STR="$(echo "$STR" | sed -E -e 's@ffn[#-]([0-9]+)@https://www.fanfiction.net/s/\1@')" +STR="$(echo "$STR" | sed -E -e 's@ao3[#-]([0-9]+)@https://archiveofourown.org/works/\1@')" +STR="$(echo "$STR" | sed -E -e 's@boost[#-]([0-9]+)@https://svn.boost.org/trac/boost/\1@')" +STR="$(echo "$STR" | sed -E -e 's@RT[#-]([0-9]+)@https://rt.cpan.org/Public/\1@')" +STR="$(echo "$STR" | sed -E -e 's@deb[#-]([0-9]+)@https://bugs.debian.org/\1@')" +STR="$(echo "$STR" | sed -E -e 's@fdo[#-]([0-9]+)@https://bugs.freedesktop.org/\1@')" +STR="$(echo "$STR" | sed -E -e 's@gcc[#-]([0-9]+)@https://gcc.gnu.org/bugzilla/\1@')" +STR="$(echo "$STR" | sed -E -e 's@kde[#-]([0-9]+)@https://bugs.kde.org/\1@')" +STR="$(echo "$STR" | sed -E -e 's@obs[#-]([0-9]+)@https://api.github.com/repos/openSUSE/open-build-service/issues/\1@')" +STR="$(echo "$STR" | sed -E -e 's@build[#-]([0-9]+)@https://api.github.com/repos/openSUSE/obs-build/issues/\1@')" +STR="$(echo "$STR" | sed -E -e 's@osc[#-]([0-9]+)@https://api.github.com/repos/openSUSE/osc/issues/\1@')" +STR="$(echo "$STR" | sed -E -e 's@poo[#-]([0-9]+)@https://progress.opensuse.org/issues/\1@')" +STR="$(echo "$STR" | sed -E -e 's@lf[#-]([0-9]+)@https://developerbugs.linux-foundation.org/\1@')" + +OPEN_UTIL="xdg-open" +type flatpak-xdg-open >/dev/null 2>/dev/null && OPEN_UTIL="flatpak-xdg-open" +exec $OPEN_UTIL "$STR" -- cgit