From b1b4c8a35ef7c202453c682a31999faf13f6ad66 Mon Sep 17 00:00:00 2001 From: Ivar Fatland Date: Tue, 15 Aug 2023 12:54:24 +0200 Subject: [PATCH] Made run script function work on all alphabetic characters instead --- init.lua | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/init.lua b/init.lua index 56b5705..61a380b 100644 --- a/init.lua +++ b/init.lua @@ -21,7 +21,7 @@ local keymap = { -- [ ] c++ --TODO find good keybindings - test_execute_file = 'e', + test_execute_script = 'e', test_debug_file = 'd', test_toggle_breakpoint = 'b', test_step_over = nil, @@ -305,19 +305,19 @@ vim.api.nvim_create_user_command( { nargs = 0 } ) ----@type function -local run_file -do - local run_script_name = ".run.sh" - - run_file = function() +---Returns function that runs the given script_name in the current working directory. +---Only implemented for Linux. ( Uses the sh command ) +---@param script_name string +---@return fun() +local function get_run_script_function(script_name) + return function() ---@type "Linux" | "Darwin" | "Windows_NT" local os_name = vim.loop.os_uname().sysname if os_name ~= "Linux" then error('run_file not implemented for non-linux platforms') end - local run_script_path = vim.fn.getcwd() .. "/" .. run_script_name + local run_script_path = vim.fn.getcwd() .. "/" .. script_name if not file_exists(run_script_path) then error( "The run script: '" .. run_script_path .. "' does not exist.\n".. @@ -329,12 +329,18 @@ do end end -vim.keymap.set( - 'n', - keymap.test_execute_file, - run_file, - { silent = true } -) +do + local alphabet = 'abcdefghijklmnopqrstuvwxyzæøåABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ' + for i = 1, #alphabet do + local char = alphabet:sub(i, i) + vim.keymap.set( + 'n', + keymap.test_execute_script .. char, + get_run_script_function("." .. char .. ".sh"), + { silent = true } + ) + end +end ---Splits the line under the cursor into multiple lines. ---Works on lines with properly opening and closing brackets: (),[],{}