Skip to content

Commit

Permalink
fix: README.md + linting
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAppSec committed Sep 6, 2024
1 parent 2925d76 commit 53dfa8d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<leader>re", -- Run: Execute Command from Line Selection
}
}
prefix = "<leader>r", -- Change base prefix to <leader>r
keys = {
run_exec = "e", -- <leader>re (Execute Command in Terminal)
},
},
},
}
```

Expand Down
1 change: 0 additions & 1 deletion lua/hacker-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ local config = {

---@class MyModule
local M = {}

---@type Config
M.config = config

Expand Down
14 changes: 7 additions & 7 deletions lua/hacker-helper/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,22 +28,22 @@ 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
local term_bufnr = nil
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
Expand Down
16 changes: 12 additions & 4 deletions plugin/hacker-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<leader>re', ':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap('v', '<leader>re', ':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>',
{ noremap = true, silent = true })
vim.api.nvim_set_keymap(
"n",
"<leader>re",
':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>',
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"v",
"<leader>re",
':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>',
{ noremap = true, silent = true }
)

0 comments on commit 53dfa8d

Please sign in to comment.