diff --git a/README.md b/README.md index 49e210e..899bac8 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,17 @@ A few Snippets to help hacking ``` -{ +# Add to plugins/hacker-helper.lua +return { + { "SirAppsec/hacker-helper.nvim", opts = { - keys = { - run_exec = "re", -- Run: Execute Command from Line Selection - } - } + prefix = "r", -- Change base prefix to r + keys = { + run_exec = "e", -- re (Execute Command in Terminal) + }, + }, + }, } ``` diff --git a/lua/hacker-helper.lua b/lua/hacker-helper.lua index 3f76469..79179b6 100644 --- a/lua/hacker-helper.lua +++ b/lua/hacker-helper.lua @@ -14,7 +14,6 @@ local config = { ---@class MyModule local M = {} - ---@type Config M.config = config diff --git a/lua/hacker-helper/module.lua b/lua/hacker-helper/module.lua index f29c881..0f65404 100644 --- a/lua/hacker-helper/module.lua +++ b/lua/hacker-helper/module.lua @@ -14,12 +14,12 @@ end -- Function to execute the current line or visual selection in an existing terminal function M.exec_line_or_selection_in_term() -- Initialize the toggleterm plugin if not already done - local ok, toggleterm = pcall(require, 'toggleterm') + local ok, toggleterm = pcall(require, "toggleterm") if ok then - toggleterm.setup { - direction = 'vertical', + toggleterm.setup({ + direction = "vertical", size = 50, - } + }) else print("toggleterm is not installed or cannot be loaded.") return @@ -28,14 +28,14 @@ function M.exec_line_or_selection_in_term() local mode = vim.api.nvim_get_mode().mode local lines = {} - if mode == 'v' then + if mode == "v" then -- Get the visually selected lines local start_pos = vim.fn.getpos("'<") local end_pos = vim.fn.getpos("'>") lines = vim.fn.getline(start_pos[2], end_pos[2]) else -- Get the current line - table.insert(lines, vim.fn.getline('.')) + table.insert(lines, vim.fn.getline(".")) end -- Find the existing terminal buffer @@ -43,7 +43,7 @@ function M.exec_line_or_selection_in_term() local buffers = vim.api.nvim_list_bufs() for _, buf in ipairs(buffers) do - if vim.api.nvim_buf_get_option(buf, 'buftype') == 'terminal' then + if vim.api.nvim_buf_get_option(buf, "buftype") == "terminal" then term_bufnr = buf break end diff --git a/plugin/hacker-helper.lua b/plugin/hacker-helper.lua index 27269cc..11d24f8 100644 --- a/plugin/hacker-helper.lua +++ b/plugin/hacker-helper.lua @@ -2,7 +2,15 @@ vim.api.nvim_create_user_command("HackerHelper", require("hacker-helper").hello, -- Key mappings for executing in terminal -- Key mappings for executing in terminal -vim.api.nvim_set_keymap('n', 're', ':lua require("hacker-helper.module").exec_line_or_selection_in_term()', - { noremap = true, silent = true }) -vim.api.nvim_set_keymap('v', 're', ':lua require("hacker-helper.module").exec_line_or_selection_in_term()', - { noremap = true, silent = true }) +vim.api.nvim_set_keymap( + "n", + "re", + ':lua require("hacker-helper.module").exec_line_or_selection_in_term()', + { noremap = true, silent = true } +) +vim.api.nvim_set_keymap( + "v", + "re", + ':lua require("hacker-helper.module").exec_line_or_selection_in_term()', + { noremap = true, silent = true } +)