Skip to content

Commit d2a3d12

Browse files
committed
Add support for arbitrary shfmt command with arguments
Make it possible to use complex shfmt commands, such as shfmt running in a docker container. Use the codefmt#formatterhelpers#ResolveFlagToArray approach seen in other formatters.
1 parent e083709 commit d2a3d12

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

autoload/codefmt/shfmt.vim

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ function! codefmt#shfmt#GetFormatter() abort
2626
\ 'and configure the shfmt_executable flag'}
2727

2828
function l:formatter.IsAvailable() abort
29-
return executable(s:plugin.Flag('shfmt_executable'))
29+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
30+
\ 'shfmt_executable')
31+
if !empty(l:cmd) && executable(l:cmd[0])
32+
return 1
33+
else
34+
return 0
35+
endif
3036
endfunction
3137

3238
function l:formatter.AppliesToBuffer() abort
@@ -48,7 +54,8 @@ function! codefmt#shfmt#GetFormatter() abort
4854
\ 'shfmt_options flag must be list or callable. Found %s',
4955
\ string(l:Shfmt_options))
5056
endif
51-
let l:cmd = [ s:plugin.Flag('shfmt_executable') ] + l:shfmt_options
57+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
58+
\ 'shfmt_executable') + l:shfmt_options
5259
try
5360
" Feature request for range formatting:
5461
" https://github.com/mvdan/sh/issues/333

doc/codefmt.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ Google's style. See https://github.com/mvdan/sh for details.
8282
Default: ['-i', '2', '-sr', '-ci'] `
8383

8484
*codefmt:shfmt_executable*
85-
The path to the shfmt executable.
85+
The path to the shfmt executable. String, list, or callable that takes no args
86+
and returns a string or a list.
8687
Default: 'shfmt' `
8788

8889
*codefmt:prettier_options*

instant/flags.vim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ call s:plugin.Flag('google_java_executable', 'google-java-format')
109109
call s:plugin.Flag('shfmt_options', ['-i', '2', '-sr', '-ci'])
110110

111111
""
112-
" The path to the shfmt executable.
112+
" The path to the shfmt executable. String, list, or callable that
113+
" takes no args and returns a string or a list.
113114
call s:plugin.Flag('shfmt_executable', 'shfmt')
114115

115116
""

0 commit comments

Comments
 (0)