summaryrefslogtreecommitdiffstats
path: root/.config/nvim/after/ftplugin/bash.lua
blob: 6e10433a94b98140b4d982210c016dce249a421f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
vim.opt_local.textwidth = vim.g.dotfiles.textwidth.sh -- gw wraps at this value
vim.opt_local.colorcolumn = "+1" -- Highlight one column after 'textwidth'
vim.opt_local.complete = {
	"o", -- 'omnifunc'
}

vim.b.autoformat = true
vim.b.format_func = function()
	local ret = vim.system({ "shfmt" }, { stdin = vim.api.nvim_buf_get_lines(0, 0, -1, false) }):wait()
	if ret.code ~= 0 then
		vim.notify("shfmt failed (" .. ret.code .. "):\n" .. ret.stderr, vim.log.levels.WARN)
		return
	end
	local view = vim.fn.winsaveview()
	vim.cmd("%!shfmt")
	vim.fn.winrestview(view)
end