Skip to content

Instantly share code, notes, and snippets.

@koga1020
Created November 26, 2022 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koga1020/c62f8b266772344f10b5bc444db1238d to your computer and use it in GitHub Desktop.
Save koga1020/c62f8b266772344f10b5bc444db1238d to your computer and use it in GitHub Desktop.
uuidgen + pngpasteを実行してimages/に画像ファイルを保存するスクリプト
local function uuid()
local command = "uuidgen | tr '[:upper:]' '[:lower:]'"
local handle, error = io.popen(command)
if not handle then
return nil, error
end
local result = handle:read("*a"):gsub("%s", "")
handle:close()
return result
end
vim.api.nvim_create_user_command("PasteImage", function()
local filename = uuid() .. ".png"
local image_path = "images/" .. filename
os.execute("pngpaste" .. " " .. image_path)
vim.fn.setline(".", "![" .. filename .. "](/" .. image_path .. ")")
end, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment