Update c.lua

This commit is contained in:
DarthMooMancer
2025-03-11 11:31:36 -04:00
parent 92f0a8fca0
commit 500112c422
+36 -5
View File
@@ -326,21 +326,52 @@ function M.run()
end end
local build_dir = project_root .. "/build" local build_dir = project_root .. "/build"
local files = vim.fn.glob(build_dir .. "/*.txt", true, true)
-- Find an executable file
local files = vim.fn.glob(build_dir .. "/*", true, true)
local project_name = nil local project_name = nil
for _, file in ipairs(files) do for _, file in ipairs(files) do
if vim.fn.match(file, "CMakeCache.txt") == -1 then -- Check if file is executable and not a directory
project_name = vim.fn.fnamemodify(file, ":r") if vim.fn.filereadable(file) == 1 and vim.fn.match(file, "CMakeCache.txt") == -1 then
project_name = file
break break
end end
end end
if not project_name then if not project_name then
print("Error: No valid project name file found in the build directory.") print("Error: No valid executable found in the build directory.")
return return
end end
M.open_float_terminal("cd " .. build_dir .. " && ." .. project_name) M.open_float_terminal("cd " .. build_dir .. " && ./" .. vim.fn.fnamemodify(project_name, ":t"))
end end
-- function M.run()
-- local current_dir = vim.fn.expand("%:p:h")
-- local project_root = current_dir:match("(.*)/src")
--
-- if not project_root then
-- print("Error: src directory not found.")
-- return
-- end
--
-- local build_dir = project_root .. "/build"
-- local files = vim.fn.glob(build_dir .. "/*.txt", true, true)
-- local project_name = nil
-- for _, file in ipairs(files) do
-- if vim.fn.match(file, "CMakeCache.txt") == -1 then
-- project_name = vim.fn.fnamemodify(file, ":r")
-- break
-- end
-- end
--
-- if not project_name then
-- print("Error: No valid project name file found in the build directory.")
-- return
-- end
--
-- M.open_float_terminal("cd " .. build_dir .. " && ./" .. project_name)
-- end
return M return M