Skip to content

Commit

Permalink
shotcut:ToggleTerm which-key
Browse files Browse the repository at this point in the history
  • Loading branch information
SirAppSec committed Sep 6, 2024
1 parent 5e21d3a commit b262209
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions lua/hacker-helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ local module = require("hacker-helper.module")
---@field opt string Your config option
---@field keys table<string, string> Key mappings
local config = {
prefix = "<leader>r", -- Default prefix for Hacker Helper
keys = {
run_exec = "<leader>re", -- Default mapping for executing in terminal
run_exec = "e", -- Default mapping for executing in terminal
},
opt = "Hello!",
}
Expand All @@ -24,16 +25,35 @@ M.setup = function(args)
-- Merge user configuration with defaults
M.config = vim.tbl_deep_extend("force", M.config, args or {})

-- Set up the key mappings, respecting user configuration
vim.api.nvim_set_keymap('n', M.config.keys.run_exec,
':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap('v', M.config.keys.run_exec,
':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>', { noremap = true, silent = true })
-- Set the key mappings dynamically based on the prefix
local full_run_exec_mapping = M.config.prefix .. M.config.keys.run_exec
vim.api.nvim_set_keymap(
"n",
full_run_exec_mapping,
':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>',
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"v",
full_run_exec_mapping,
':lua require("hacker-helper.module").exec_line_or_selection_in_term()<CR>',
{ noremap = true, silent = true }
)

-- Register a description for the <leader>r prefix with which-key (if available)
if package.loaded["which-key"] then
require("which-key").register({
["<leader>x"] = { name = "Hacker Helper" },
["<leader>xe"] = {
":lua require('hacker-helper.module').exec_line_or_selection_in_term()<CR>",
"Run Command in Terminal",
},
})
end
end

M.hello = function()
return module.my_first_function(M.config.opt)
end


return M

0 comments on commit b262209

Please sign in to comment.