added run command

This commit is contained in:
Ivar Fatland
2023-08-13 13:52:05 +02:00
parent fcc0339226
commit f684938067
+38 -10
View File
@@ -264,8 +264,9 @@ local function packer_startup(use)
end end
do ---@param name string
local function file_exists(name) ---@return boolean
local function file_exists(name)
local f = io.open(name,"r") local f = io.open(name,"r")
if f~=nil then if f~=nil then
@@ -274,14 +275,14 @@ do
else else
return false return false
end end
end end
-- Opens a default .snippets file for the filetype you are currently editing in a horizontal split pane. -- Opens a default .snippets file for the filetype you are currently editing in a horizontal split pane.
-- If the .snippets file does not exist, it will be created. -- If the .snippets file does not exist, it will be created.
-- This requires the snippets folder to exist in the config folder. -- This requires the snippets folder to exist in the config folder.
-- If the folder does not exist, the command will print out a helpful error message showing what the path -- If the folder does not exist, the command will print out a helpful error message showing what the path
-- should look like. -- should look like.
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
'S', 'S',
function () function ()
---@type string ---@type string
@@ -302,9 +303,36 @@ do
vim.api.nvim_command(('SnippyEdit %s'):format(snippets_path)) vim.api.nvim_command(('SnippyEdit %s'):format(snippets_path))
end, end,
{ nargs = 0 } { nargs = 0 }
) )
---@type function
local run_file
do
local run_script_name = "run.sh"
run_file = 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
if not file_exists(run_script_path) then
error( "The run script: '" .. run_script_path .. "' does not exist")
end
vim.cmd('!sh ' .. run_script_path)
end
end end
vim.keymap.set(
'n',
keymap.test_execute_file,
run_file,
{ silent = true }
)
---Splits the line under the cursor into multiple lines. ---Splits the line under the cursor into multiple lines.
---Works on lines with properly opening and closing brackets: (),[],{} ---Works on lines with properly opening and closing brackets: (),[],{}
---Starts at the cursor position and moves to the right until it finds an opening bracket. ---Starts at the cursor position and moves to the right until it finds an opening bracket.