Skip to content

Commit 9033599

Browse files
authored
Merge pull request #152 from funous/shfmt_executable_list
Add support for arbitrary shfmt command with arguments
2 parents e083709 + a0914a5 commit 9033599

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

Diff for: autoload/codefmt/shfmt.vim

+9-2
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

Diff for: doc/codefmt.txt

+2-1
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*

Diff for: instant/flags.vim

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ call s:plugin.flags.autopep8_executable.AddCallback(
5252
\ maktaba#function#FromExpr('codefmt#autopep8#InvalidateVersion()'), 0)
5353

5454
""
55-
" The path to the clang-format executable.
55+
" The path to the clang-format executable. String, list, or callable that
56+
" takes no args and returns a string or a list.
5657
call s:plugin.Flag('clang_format_executable', 'clang-format')
5758
" Invalidate cache of detected clang-format version when this is changed, regardless
5859
" of {value} arg.
@@ -109,7 +110,8 @@ call s:plugin.Flag('google_java_executable', 'google-java-format')
109110
call s:plugin.Flag('shfmt_options', ['-i', '2', '-sr', '-ci'])
110111

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

115117
""

0 commit comments

Comments
 (0)