add command runner to nvim
This commit is contained in:
parent
dd1c82e804
commit
2054a68af0
5 changed files with 47 additions and 3 deletions
36
home/.config/nvim/lua/command_runner.lua
Normal file
36
home/.config/nvim/lua/command_runner.lua
Normal file
|
@ -0,0 +1,36 @@
|
|||
local M = {}
|
||||
|
||||
function M.run_shell_command_under_cursor()
|
||||
local cmd = vim.api.nvim_get_current_line()
|
||||
|
||||
if cmd == "" then
|
||||
print("No command on this line.")
|
||||
return
|
||||
end
|
||||
|
||||
-- Run command and capture output
|
||||
local output = vim.fn.systemlist(cmd)
|
||||
|
||||
-- Save current window to return later
|
||||
local current_win = vim.api.nvim_get_current_win()
|
||||
|
||||
-- Move to the right window (assumes it's already split)
|
||||
vim.cmd("wincmd l")
|
||||
|
||||
-- Optional: clear buffer before writing
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, {})
|
||||
|
||||
-- Set output in current buffer (right side)
|
||||
vim.api.nvim_buf_set_lines(0, 0, -1, false, output)
|
||||
|
||||
-- Optional: make it editable plain text
|
||||
vim.bo.filetype = "text"
|
||||
vim.bo.modifiable = true
|
||||
vim.bo.readonly = false
|
||||
|
||||
-- Return to the left window
|
||||
vim.api.nvim_set_current_win(current_win)
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue