From 6822a716853ba9a8d2345a3583000ca378b22653 Mon Sep 17 00:00:00 2001 From: pika Date: Sat, 22 Mar 2025 10:57:30 +0100 Subject: [PATCH] fix: when using cursor or vscode, use only keymap settings, else use everything --- init.lua | 81 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/init.lua b/init.lua index 68f2a4d..13aae1b 100644 --- a/init.lua +++ b/init.lua @@ -1,44 +1,53 @@ -require("pika.core") -require("pika.lazy") +if vim.g.vscode then + require("pika.core") +else + require("pika.core") + require("pika.lazy") --- ─< Call the function to set the desired colorscheme >──────────────────────────────── --- ╭──────────────────────────────────────────────────────╮ --- │ themes are under ./lua/pika/plugins/colorschemes.lua │ --- ╰──────────────────────────────────────────────────────╯ + -- ─< Call the function to set the desired colorscheme >──────────────────────────────── + -- ╭──────────────────────────────────────────────────────╮ + -- │ themes are under ./lua/pika/plugins/colorschemes.lua │ + -- ╰──────────────────────────────────────────────────────╯ -vim.cmd.colorscheme("oldschool") + vim.cmd.colorscheme("oldschool") --- Keybind for saving clipboard screenshot and inserting a Markdown link -vim.api.nvim_set_keymap("n", "ps", ":lua SaveScreenshotAndInsertLink()", { noremap = true, silent = true }) + -- Keybind for saving clipboard screenshot and inserting a Markdown link + vim.api.nvim_set_keymap( + "n", + "ps", + ":lua SaveScreenshotAndInsertLink()", + { noremap = true, silent = true } + ) -function SaveScreenshotAndInsertLink() - -- Prompt for Hugo base directory if needed + 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") + -- 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") + -- 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 = "![](/images/screenshots/" .. img_name .. ")\n" + vim.api.nvim_put({ img_markdown }, "c", true, true) + + print("Screenshot saved and link added: " .. full_path) 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 = "![](/images/screenshots/" .. img_name .. ")\n" - vim.api.nvim_put({ img_markdown }, "c", true, true) - - print("Screenshot saved and link added: " .. full_path) end