From 2054a68af0b76440438e6f888bd5bf3fcebf294e Mon Sep 17 00:00:00 2001 From: Artur Gurgul1 Date: Fri, 8 Aug 2025 07:55:29 +0200 Subject: [PATCH] add command runner to nvim --- home/.config/nvim/init.lua | 3 +- home/.config/nvim/lua/command_runner.lua | 36 ++++++++++++++++++++++++ home/.config/nvim/lua/keymaps.lua | 5 ++++ recipes/nvim.yml | 5 ++-- recipes/ruby/debian.yml | 1 + 5 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 home/.config/nvim/lua/command_runner.lua diff --git a/home/.config/nvim/init.lua b/home/.config/nvim/init.lua index 1f37ecf..3b15ec1 100644 --- a/home/.config/nvim/init.lua +++ b/home/.config/nvim/init.lua @@ -1,4 +1,5 @@ +require("command_runner") require("plugins") require("options") require("keymaps") -require("lsp") \ No newline at end of file +require("lsp") diff --git a/home/.config/nvim/lua/command_runner.lua b/home/.config/nvim/lua/command_runner.lua new file mode 100644 index 0000000..012cb17 --- /dev/null +++ b/home/.config/nvim/lua/command_runner.lua @@ -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 + diff --git a/home/.config/nvim/lua/keymaps.lua b/home/.config/nvim/lua/keymaps.lua index 48e81e4..4f469ea 100644 --- a/home/.config/nvim/lua/keymaps.lua +++ b/home/.config/nvim/lua/keymaps.lua @@ -5,6 +5,11 @@ map('n', 'fg', require('telescope.builtin').live_grep, { desc = "Live gr map('n', 'fb', require('telescope.builtin').buffers, { desc = "Buffers" }) map('n', 'fh', require('telescope.builtin').help_tags, { desc = "Help tags" }) +vim.keymap.set("n", "zr", function() + require("command_runner").run_shell_command_under_cursor() +end, { desc = "Run shell command under cursor and show output in right split" }) + + -- Project-specific ignored dirs for Telescope local function load_local_ignore() local cwd = vim.fn.getcwd() diff --git a/recipes/nvim.yml b/recipes/nvim.yml index 34d8313..d5492eb 100644 --- a/recipes/nvim.yml +++ b/recipes/nvim.yml @@ -5,8 +5,9 @@ packages: repository: url: https://github.com/neovim/neovim.git branch: release-0.11 + version: 0.11 steps: - make distclean - - make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX=$HOME/.local - - make install + - make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX=$PREFIX + - $SUDO make install diff --git a/recipes/ruby/debian.yml b/recipes/ruby/debian.yml index b715b8a..0079b0f 100644 --- a/recipes/ruby/debian.yml +++ b/recipes/ruby/debian.yml @@ -16,6 +16,7 @@ packages: repository: url: https://github.com/ruby/ruby.git branch: v3_4_5 + version: 3.4.5 steps: - ./autogen.sh