diff --git a/modules/home-manager/vim/config/lua/core/keymaps.lua b/modules/home-manager/vim/config/lua/core/keymaps.lua index c87115b..82178b1 100644 --- a/modules/home-manager/vim/config/lua/core/keymaps.lua +++ b/modules/home-manager/vim/config/lua/core/keymaps.lua @@ -1,7 +1,9 @@ local map = require("utils.mappings") local f = require("utils.functions") local fmt = require("utils.icons").fmt +local fn = require("utils.functions") local l, cmd, rcmd, lua = map.leader, map.cmd, map.rcmd, map.lua +local freeze, freeze_selection = fn.freeze, fn.freeze_selection return { i = { @@ -41,7 +43,7 @@ return { [l("ct")] = { cmd("CloakToggle"), "Cloak Toggle" }, -- Freeze - [l("sc")] = { cmd("Freeze"), "Take code screenshot" }, + [l("sc")] = { freeze(), "Take code screenshot" }, -- Rest [l("rr")] = { cmd("Rest run"), "Run request in Rest" }, @@ -261,7 +263,7 @@ return { [l(";")] = { f.comment_selection, fmt("Comment", "Comment selection") }, -- Freeze - [l("sc")] = { cmd("'<,'>Freeze"), "Take code screenshot" }, + [l("sc")] = { freeze_selection(), "Take code screenshot" }, -- gitsigns [l("gr")] = { cmd("Gitsigns reset_hunk"), fmt("Restore", "Revert hunk") }, diff --git a/modules/home-manager/vim/config/lua/plugins/tools/freeze.lua b/modules/home-manager/vim/config/lua/plugins/tools/freeze.lua index d5a5518..c0333e1 100644 --- a/modules/home-manager/vim/config/lua/plugins/tools/freeze.lua +++ b/modules/home-manager/vim/config/lua/plugins/tools/freeze.lua @@ -4,7 +4,7 @@ return { require("charm-freeze").setup({ command = "freeze", output = function() - return "./" .. os.date("%Y-%m-%d") .. "_freeze.png" + return "./" .. "._freeze.png" end, show_line_numbers = true, theme = "catppuccin-mocha", diff --git a/modules/home-manager/vim/config/lua/utils/functions.lua b/modules/home-manager/vim/config/lua/utils/functions.lua index 1aeb802..751c77a 100644 --- a/modules/home-manager/vim/config/lua/utils/functions.lua +++ b/modules/home-manager/vim/config/lua/utils/functions.lua @@ -17,6 +17,35 @@ local select = function(prompt, callback) end) end +M.freeze = function() + local path = "./._freeze.png" + + -- Execute the 'Freeze' command on the selected range + vim.cmd("Freeze") + + -- Run the shell command 'wl-copy ' after 'Freeze' completes + vim.fn.system("wl-copy < " .. path) + vim.fn.system("rm " .. path) +end + +M.freeze_selection = function() + local path = "./._freeze.png" + + -- Save and exit visual mode + vim.cmd("normal! gv") + + -- Get the positions of the start and end of the visual selection + local start_line = vim.fn.getpos("'<")[2] -- line number of the start of selection + local end_line = vim.fn.getpos("'>")[2] -- line number of the end of selection + + -- Execute the 'Freeze' command on the selected range + vim.cmd(start_line .. "," .. end_line .. "Freeze") + + -- Run the shell command 'wl-copy ' after 'Freeze' completes + vim.fn.system("wl-copy < " .. path) + vim.fn.system("rm " .. path) +end + M.set_filetype = function() input("Set filetype: ", function(value) vim.bo[0].filetype = value