Skip to content

Add support for arbitrary shfmt command with arguments #152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions autoload/codefmt/shfmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ function! codefmt#shfmt#GetFormatter() abort
\ 'and configure the shfmt_executable flag'}

function l:formatter.IsAvailable() abort
return executable(s:plugin.Flag('shfmt_executable'))
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
\ 'shfmt_executable')
if !empty(l:cmd) && executable(l:cmd[0])
return 1
else
return 0
endif
endfunction

function l:formatter.AppliesToBuffer() abort
Expand All @@ -48,7 +54,8 @@ function! codefmt#shfmt#GetFormatter() abort
\ 'shfmt_options flag must be list or callable. Found %s',
\ string(l:Shfmt_options))
endif
let l:cmd = [ s:plugin.Flag('shfmt_executable') ] + l:shfmt_options
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
\ 'shfmt_executable') + l:shfmt_options
try
" Feature request for range formatting:
" https://github.com/mvdan/sh/issues/333
Expand Down
3 changes: 2 additions & 1 deletion doc/codefmt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ Google's style. See https://github.com/mvdan/sh for details.
Default: ['-i', '2', '-sr', '-ci'] `

*codefmt:shfmt_executable*
The path to the shfmt executable.
The path to the shfmt executable. String, list, or callable that takes no args
and returns a string or a list.
Comment on lines -85 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you manually edited this without updating the source in flags.vim it's generated from, so it'll get reverted next time someone regenerates the help docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the flags.vim and checked that vimdoc generates the same string. I've also updated flags.vim to have the source for the changes I've done manually in #124. I can split it into another PR if it's preferred.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Same PR is fine for this, no worries.

Default: 'shfmt' `

*codefmt:prettier_options*
Expand Down
6 changes: 4 additions & 2 deletions instant/flags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ call s:plugin.flags.autopep8_executable.AddCallback(
\ maktaba#function#FromExpr('codefmt#autopep8#InvalidateVersion()'), 0)

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

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

""
Expand Down