author: Chenzhu-Xie name: Library/xczphysics/CONFIG/Copy_as/page_title/Github_Url tags: meta/library
#forward #external #wiki
function: encode_url
-- description: Copy the GitHub URL of the current page to clipboard
local function encode_url(s)
local parts = {}
for i = 1, #s do
local c = s:sub(i, i)
if c == " " then
parts[#parts+1] = "%20"
else
parts[#parts+1] = c
end
end
return table.concat(parts)
end
command.define {
-- name = "Copy: Page Github Url",
name = "Page: Copy Github",
key = "Shift-Alt-g",
run = function()
-- Construct GitHub URL
local base = "https://github.com/ChenZhu-Xie/xczphysics_SilverBullet/blob/main/"
-- local base = "github:ChenZhu-Xie/xczphysics_SilverBullet/"
local url = base .. encode_url(editor.getCurrentPath())
-- Copy to clipboard
editor.copyToClipboard(url)
-- editor.flashNotification("Copied: GitHub URL ✅", "info")
editor.flashNotification("GitHub URL ✅", "info")
editor.flashNotification(url, "info")
end
}