formatted + added project formatter that respects .gitignore

This commit is contained in:
foxora 2026-03-03 04:50:29 +00:00
parent 3e14220569
commit 2c69e1f116
4 changed files with 24 additions and 10 deletions

View file

@ -1,10 +1,13 @@
vim.keymap.set("n", "<leader>P", "<cmd>ConformProject<cr>", { noremap = true, silent = true })
vim.keymap.set("n", "<leader>P", function()
vim.api.nvim_exec_autocmds("User", { pattern = "ConformProject" })
vim.cmd("ConformProject")
end, { noremap = true, silent = true })
vim.api.nvim_create_user_command("ConformProject", function()
local conform = require("conform")
local root = vim.fn.getcwd()
-- Use git to get files (respects .gitignore)
-- respects .gitignore
local handle = io.popen(string.format("cd %s && git ls-files --cached --others --exclude-standard", root))
if not handle then
@ -18,7 +21,9 @@ vim.api.nvim_create_user_command("ConformProject", function()
end
handle:close()
-- Format each file
-- format each file
-- TODO: maybe run each formatter on the directory instead as it may be faster
-- although that would actually mean we can't count what files were formatted so i don't know
local formatted_count = 0
for _, filepath in ipairs(files) do
local bufnr = vim.fn.bufadd(filepath)
@ -42,6 +47,7 @@ return {
{
"conform.nvim",
enabled = nixCats("format") or false,
event = "User ConformProject", -- also will load when we format the entire project yayayayy :333
keys = {
{ "<leader>p", desc = "Format File (pretty :3)" },
},