From 887f35a80c752009c2a2230ffb5ab27a6576fb24 Mon Sep 17 00:00:00 2001 From: Soispha Peetz Date: Sun, 29 Nov 2026 20:57:07 +0100 Subject: modules/nvim/mappings: Run the shell command in `X` relative to the current buffer --- modules/by-name/nv/nvim/mappings/default.nix | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/by-name/nv/nvim/mappings/default.nix b/modules/by-name/nv/nvim/mappings/default.nix index 4e1a57a7..2a1bacb0 100644 --- a/modules/by-name/nv/nvim/mappings/default.nix +++ b/modules/by-name/nv/nvim/mappings/default.nix @@ -253,7 +253,25 @@ { mode = ["n"]; key = "X"; - action = "!!$SHELL "; + action.__raw = '' + local cur_line = tostring(vim.api.nvim_get_current_line()); + vim.api.nvim_del_current_line(); + + local output = vim.system( + { vim.env.SHELL; "-c"; cur_line; }, + { + text = true; + cwd = vim.fs.dirname(vim.api.nvim_buf_get_name(0)); + } + ):wait() + + if output.stdout ~= "" then + vim.api.nvim_put(vim.split(output.stdout, "\n"), "", false, false) + end + if output.stderr ~= "" then + vim.api.nvim_put(vim.split(output.stderr, "\n"), "", false, false) + end + ''; options.desc = "Read the current line and execute that line in your $SHELL. The resulting output will replace the curent line that was being executed."; } { -- cgit v1.3.1