nvim: fix handling of tabs/spaces for shfmt formatter

This commit is contained in:
Fernando Schauenburg 2024-07-19 22:39:44 +02:00
parent 73da48e6e6
commit 24fe53f1cc

View file

@ -1,3 +1,26 @@
local shfmt = function()
local indent = 0 -- Assume tabs initially.
if vim.opt.expandtab:get() then
local shiftwidth = vim.opt.shiftwidth:get()
if shiftwidth == 0 then
indent = vim.opt.tabstop:get()
else
indent = shiftwidth
end
end
return {
exe = "shfmt",
-- stylua: ignore start
args = {
"--indent", indent, -- 0 for tabs, >0 for number of spaces.
"--keep-padding", -- Keep column alignment paddings.
},
-- stylua: ignore end
stdin = true,
}
end
return {
"mhartington/formatter.nvim",
@ -28,7 +51,7 @@ return {
lua = { builtin.lua.stylua },
markdown = { builtin.markdown.prettier },
python = {}, -- TODO: pick one
sh = { builtin.sh.shfmt },
sh = { shfmt() },
zsh = { builtin.zsh.beautysh },
-- stylua: ignore end
},