diff --git a/config/nvim/lua/fschauen/plugins/formatter.lua b/config/nvim/lua/fschauen/plugins/formatter.lua index ccd4a0c..ee0eb63 100644 --- a/config/nvim/lua/fschauen/plugins/formatter.lua +++ b/config/nvim/lua/fschauen/plugins/formatter.lua @@ -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 },