Created
November 26, 2022 11:56
-
-
Save koga1020/c62f8b266772344f10b5bc444db1238d to your computer and use it in GitHub Desktop.
uuidgen + pngpasteを実行してimages/に画像ファイルを保存するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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