addet a function, to automatically store screenshots to hugo sites with the <leader>ps keybind
This commit is contained in:
parent
835432435f
commit
d57b27fb73
1 changed files with 35 additions and 0 deletions
35
init.lua
35
init.lua
|
@ -7,3 +7,38 @@ require("pika.lazy")
|
||||||
-- ╰──────────────────────────────────────────────────────╯
|
-- ╰──────────────────────────────────────────────────────╯
|
||||||
|
|
||||||
vim.cmd.colorscheme("darkearth")
|
vim.cmd.colorscheme("darkearth")
|
||||||
|
|
||||||
|
-- Keybind for saving clipboard screenshot and inserting a Markdown link
|
||||||
|
vim.api.nvim_set_keymap("n", "<leader>ps", ":lua SaveScreenshotAndInsertLink()<CR>", { noremap = true, silent = true })
|
||||||
|
|
||||||
|
function SaveScreenshotAndInsertLink()
|
||||||
|
-- Prompt for Hugo base directory if needed
|
||||||
|
|
||||||
|
-- Define the Hugo base directory and screenshot subfolder path
|
||||||
|
local base_dir
|
||||||
|
local current_file_dir = vim.fn.expand("%:p:h")
|
||||||
|
|
||||||
|
-- Detect base dir by looking for the Hugo structure, or prompt if not found
|
||||||
|
if current_file_dir:match("/content/") then
|
||||||
|
base_dir = current_file_dir:match("(.*)/content/")
|
||||||
|
else
|
||||||
|
-- Prompt for Hugo base directory if automatic detection fails
|
||||||
|
base_dir = vim.fn.input("Enter base directory of your Hugo site: ", "", "file")
|
||||||
|
end
|
||||||
|
|
||||||
|
local img_folder = base_dir .. "/static/images/screenshots/"
|
||||||
|
vim.fn.mkdir(img_folder, "p") -- Ensure the directory exists
|
||||||
|
|
||||||
|
-- Define the image name and full path
|
||||||
|
local img_name = os.date("%Y-%m-%d_%H-%M-%S") .. ".png"
|
||||||
|
local full_path = img_folder .. img_name
|
||||||
|
|
||||||
|
-- Save clipboard image as binary PNG file using wl-paste
|
||||||
|
os.execute("wl-paste --type image/png > " .. full_path)
|
||||||
|
|
||||||
|
-- Insert markdown image link at cursor position
|
||||||
|
local img_markdown = "\n"
|
||||||
|
vim.api.nvim_put({ img_markdown }, "c", true, true)
|
||||||
|
|
||||||
|
print("Screenshot saved and link added: " .. full_path)
|
||||||
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue