From 18d59383632fcfbacc1f4d05b9f93bd67baf5366 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Mon, 15 Jan 2018 15:39:08 +0100 Subject: [PATCH] Add shfmt as a default formatter for shell files Taking into account vim indentation style dynamically (shiftwidth or tabs). --- README.md | 3 +++ plugin/defaults.vim | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/README.md b/README.md index 613e992..3bd9226 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,9 @@ Here is a list of formatprograms that are supported by default, and thus will be It is a JSON file fixer/formatter for humans using (relaxed) JSON5. It fixes various failures while humans writing JSON and formats JSON codes. It can be installed with `npm install -g fixjson`. More info is available at https://github.com/rhysd/fixjson. +* `shfmt` for __Shell__. + A shell formatter written in Go supporting POSIX Shell, Bash and mksh that can be installed with `go get -u mvdan.cc/sh/cmd/shfmt`. See https://github.com/mvdan/sh for more info. + ## Help, the formatter doesn't work as expected! diff --git a/plugin/defaults.vim b/plugin/defaults.vim index c5f4451..9f18371 100644 --- a/plugin/defaults.vim +++ b/plugin/defaults.vim @@ -453,3 +453,12 @@ endif if !exists('g:formatters_elixir') let g:formatters_elixir = ['mix_format'] endif + +" Shell +if !exists('g:formatdef_shfmt') + let g:formatdef_shfmt = '"shfmt -i ".(&expandtab ? shiftwidth() : "0")' +endif + +if !exists('g:formatters_sh') + let g:formatters_sh = ['shfmt'] +endif