aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2020-03-16 23:55:04 +0100
committerMatěj Cepl <mcepl@cepl.eu>2020-03-16 23:55:59 +0100
commita894e312dcf263f18a398c93252617aeaf5ca687 (patch)
treeca2371d1ed0cc3d43bc3940f25017c81ef5a1feb /init.lua
parent1bc6609f349b6530490ee6a6e22846f4fec01245 (diff)
downloadvis-jump-a894e312dcf263f18a398c93252617aeaf5ca687.tar.gz
Add function to shorten selected URL.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/init.lua b/init.lua
index b01fb3f..2624aa4 100644
--- a/init.lua
+++ b/init.lua
@@ -11,10 +11,44 @@ local function get_query()
return str:sub(from, to)
end
+local function replace_URLs()
+ local line = vis.win.selection.line
+ local str = vis.win.file.lines[line]
+
+ str = str:gsub("https://github.com/(.*)/issues/(%d+)", "gh#%1#%2")
+ str = str:gsub("https://github.com/(.*)/pull/(%d+)", "gh#%1#%2")
+ str = str:gsub("https://gitlab.com/(.*)/issues/(%d+)", "gl#%1#%2")
+ str = str:gsub("https://gitlab.com/(.*)/pull/(%d+)", "gl#%1#%2")
+ str = str:gsub("https://sourceforge.net/support/tracker.php%?aid=(%d+)", "sh#%1")
+ str = str:gsub("https://sf.net/support/tracker.php%?aid=(%d+)", "sh#%1")
+ str = str:gsub("https://sourceforge.net/p/(.*)/patches/(%d+)/", "shp#%1#%2")
+ str = str:gsub("https://sourceforge.net/p/(.*)/bugs/(%d+)/", "shb#%1#%2")
+ str = str:gsub("https://sf.net/support/p/(.*)/patches/(%d+)/", "shp#%1#%2")
+ str = str:gsub("https://sf.net/support/p/(.*)/bugs/(%d+)/", "shb#%1#%2")
+ str = str:gsub("https://bitbucket.org/(.*)/issues/(%d+)/", "bt#%1#%2")
+ str = str:gsub("https://build.suse.de/request/show/(%d+)", "ssr#%1")
+ str = str:gsub("https://build.opensuse.org/request/show/(%d+)", "ssr#%1")
+ str = str:gsub("https://bugzilla.opensuse.org/show_bug.cgi%?id=(%d+)", "boo#%1")
+ str = str:gsub("https://bugzilla.opensuse.org/(%d+)", "boo#%1")
+ str = str:gsub("https://bugzilla.suse.com/show_bug.cgi%?id=(%d+)", "bsc#%1")
+ str = str:gsub("https://bugzilla.suse.com/(%d+)", "bsc#%1")
+ str = str:gsub("https://jira.suse.com/browse/(%d+)", "jsc#%1")
+ str = str:gsub("https://bugs.python.org/issue(%d+)", "bpo#%1")
+ str = str:gsub("https://bugs.launchpad.net/[^]+/+bug/(%d+)", "lp#%1")
+
+ vis.win.file.lines[line] = str
+end
+
vis:map(vis.modes.NORMAL, "gx", function()
local cur_word = get_query()
+ -- https://bugzilla.suse.com/show_bug.cgi?id=1130840
-- https://bugs.freedesktop.org/show_bug.cgi?id=103807 x
-- https://www.damejidlo.cz/potrefena-husa-vinohrady
-- gh#python/cpython#7778 or bpo#34032
os.execute("osurl '" .. cur_word .. "'")
end, "Jump to URL")
+
+-- https://en.opensuse.org/openSUSE:Packaging_Patches_guidelines#Current_set_of_abbreviations
+vis:map(vis.modes.NORMAL, "gG", function()
+ replace_URLs()
+end, "Shorten URLs")