From 34c63dd99f852fd898047266fe1a1dedf451f0ab Mon Sep 17 00:00:00 2001 From: tiyn Date: Sat, 9 Mar 2024 03:52:26 +0100 Subject: [PATCH] nvim: added shell formatter --- .config/nvim/init.lua | 53 ++++++++++++++-------------- .config/nvim/lua/plugins/conform.lua | 12 +++++-- .config/nvim/lua/plugins/mason.lua | 6 +++- 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 98806f1..1e53b3c 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,4 +1,4 @@ -vim.o.go = 'a' +vim.o.go = "a" vim.o.showmode = false -- disable netrw @@ -6,11 +6,11 @@ vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 -- enable mouse for all modes -vim.o.mouse = 'a' -vim.o.clipboard = 'unnamedplus' +vim.o.mouse = "a" +vim.o.clipboard = "unnamedplus" -- basic color settings -vim.o.background = 'dark' +vim.o.background = "dark" -- setting Tab-length vim.o.expandtab = true @@ -61,10 +61,10 @@ vim.o.nobackup = true vim.o.nowritebackup = true -- set completeopt to have a better completion experience -vim.o.completeopt = 'menuone,noselect' +vim.o.completeopt = "menuone,noselect" -- set completion option for command mode -vim.o.wildmode = 'longest:full,full' +vim.o.wildmode = "longest:full,full" -- minimum number of lines around the cursor vim.o.scrolloff = 10 @@ -78,14 +78,14 @@ vim.o.undofile = true vim.o.undodir = vim.env.XDG_CACHE_HOME .. "/vim/undo" -- python programs to use -vim.g.python_host_prog = '/usr/bin/python2' -vim.g.python3_host_prog = '/usr/bin/python3' +vim.g.python_host_prog = "/usr/bin/python2" +vim.g.python3_host_prog = "/usr/bin/python3" -- folding -vim.o.foldcolumn = '0' +vim.o.foldcolumn = "0" vim.o.foldlevel = 99 vim.o.foldlevelstart = 99 -vim.o.foldexpr = 'expr' +vim.o.foldexpr = "expr" vim.o.foldenable = true vim.o.conceallevel = 0 vim.g.markdown_folding = 1 @@ -98,34 +98,35 @@ vim.o.textwidth = 80 -- read files correctly vim.filetype.add({ extension = { - c = 'c', - h = 'c', - html = 'html', - java = 'java', - js = 'javascript', - lua = 'lua', - md = 'markdown', - nim = 'nim', - py = 'python', - sage = 'python', - tex = 'tex', - } + c = "c", + h = "c", + html = "html", + java = "java", + js = "javascript", + lua = "lua", + md = "markdown", + nim = "nim", + py = "python", + sage = "python", + sh = "shell", + tex = "tex", + }, }) -- set mapleader for hotkeys vim.g.mapleader = "," -- load general mapped keys -require('style') +require("style") -- load dictionaries and helper functions -require('dictionaries') +require("dictionaries") -- load plugins (autoload all files in plugin folder) -require('loadplugins') +require("loadplugins") -- load general mapped keys -require('keymap') +require("keymap") vim.cmd([[ set foldopen-=hor diff --git a/.config/nvim/lua/plugins/conform.lua b/.config/nvim/lua/plugins/conform.lua index 6b72fa8..0ceb713 100644 --- a/.config/nvim/lua/plugins/conform.lua +++ b/.config/nvim/lua/plugins/conform.lua @@ -5,10 +5,12 @@ return { config = function() require("conform").setup({ formatters_by_ft = { - python = { "isort", "yapf" }, + lua = { "stylua" }, markdown = { "mdformat" }, + python = { "isort", "yapf" }, + sh = { "beautysh" }, + shell = { "beautysh" }, tex = { "latexindent" }, - lua = { "stylua" }, yaml = { "yamlfmt" }, }, }) @@ -18,6 +20,12 @@ return { { "-y=defaultIndent: ' '" } ), } + require("conform").formatters.beautysh = { + args = require("conform.util").extend_args( + require("conform.formatters.beautysh").args, + { "--indent-size=2", "--force-function-style=fnpar" } + ), + } end, }, } diff --git a/.config/nvim/lua/plugins/mason.lua b/.config/nvim/lua/plugins/mason.lua index eefc211..dd625ef 100644 --- a/.config/nvim/lua/plugins/mason.lua +++ b/.config/nvim/lua/plugins/mason.lua @@ -9,7 +9,7 @@ return { require("null-ls").setup({ sources = { -- latex - require("null-ls").builtins.formatting.latexindent, + -- require("null-ls").builtins.formatting.latexindent, -- lua require("null-ls").builtins.formatting.stylua, -- markdown @@ -17,6 +17,8 @@ return { -- python require("null-ls").builtins.formatting.isort, require("null-ls").builtins.formatting.yapf, + -- shell + -- require("null-ls").builtins.formatting.beautysh, -- yaml require("null-ls").builtins.formatting.yamlfmt, } @@ -37,6 +39,8 @@ return { -- python "isort", "yapf", + -- shell + "beautysh", -- yaml "yamlfmt", }