[vim/vim] runtime(sh): set shellcheck as the compiler for supported shells (PR #16311)

34 views
Skip to first unread message

Luca Saccarola

unread,
Dec 26, 2024, 5:48:04 PM12/26/24
to vim/vim, Subscribed

Hi,
I think we should be setting shellcheck has the compiler for every shellcheck supported shell.
https://www.shellcheck.net/wiki/SC1071.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/16311

Commit Summary

  • ab4b5ae runtime(sh): set shellcheck as the compiler for supported shells

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311@github.com>

Gary Johnson

unread,
Dec 26, 2024, 6:27:56 PM12/26/24
to reply+ACY5DGG23ZGVSUAIA5...@reply.github.com, vim...@googlegroups.com
On 2024-12-26, Luca Saccarola wrote:
> Hi,
> I think we should be setting shellcheck has the compiler for every shellcheck
> supported shell.

Doesn't shellcheck need the "-f gcc" and maybe "-x" options?

I wrote a command and function to use shellcheck as a 'makeprg'
a while back and set this so that Vim could properly parse the
output:

let &makeprg = "shellcheck -f gcc -x"

Regards,
Gary

vim-dev ML

unread,
Dec 26, 2024, 6:28:24 PM12/26/24
to vim/vim, vim-dev ML, Your activity

On 2024-12-26, Luca Saccarola wrote:
> Hi,
> I think we should be setting shellcheck has the compiler for every shellcheck
> supported shell.

Doesn't shellcheck need the "-f gcc" and maybe "-x" options?

I wrote a command and function to use shellcheck as a 'makeprg'
a while back and set this so that Vim could properly parse the
output:

let &makeprg = "shellcheck -f gcc -x"

Regards,
Gary


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311/c2563167563@github.com>

Enno

unread,
Dec 27, 2024, 12:31:34 AM12/27/24
to vim/vim, vim-dev ML, Comment

While at it, shouldn't one check for executable('shellcheck') as well?

In its absence, fall back to

CompilerSet makeprg=bash\ -n
CompilerSet errorformat=%f:\ line\ %l:\ %m

if g:is_bash is set


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/c2563335701@github.com>

Luca Saccarola

unread,
Dec 27, 2024, 3:21:15 AM12/27/24
to vim/vim, vim-dev ML, Comment

Doesn't shellcheck need the "-f gcc" and maybe "-x" options?

This is set when you do :compiler shellcheck. That command will load the $VIMRUNTIME/compiler/shellcheck which if we look inside of it will set the errorformat and makeprg correctly.

While at it, shouldn't one check for executable('shellcheck') as well?

Yes, it is probably a good idea

In its absence, fall back to

I don't know. I think we should make a new compiler for bash and it is probably good for another PR


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/c2563447885@github.com>

Luca Saccarola

unread,
Dec 27, 2024, 3:26:51 AM12/27/24
to vim/vim, vim-dev ML, Push

@saccarosium pushed 1 commit.

  • 1185316 runtime(sh): set shellcheck as the compiler for supported shells


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311/before/ab4b5ae6e050e2e05075211670097d9e6fecc17c/after/1185316b6929dce00142132ac65528338fa1ba73@github.com>

Christian Brabandt

unread,
Dec 27, 2024, 10:19:50 AM12/27/24
to vim/vim, vim-dev ML, Comment

@chrisbra commented on this pull request.


In runtime/ftplugin/sh.vim:

> @@ -44,15 +44,21 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
-if get(b:, "is_bash", 0)
+let s:is_sh = get(b:, "is_bash", 0)

I suppose this should have been testing for b:is_sh instead?


In runtime/ftplugin/sh.vim:

> @@ -44,15 +44,21 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
-if get(b:, "is_bash", 0)
+let s:is_sh = get(b:, "is_bash", 0)
+let s:is_bash = get(b:, "is_bash", 0)
+let s:is_kornshell = get(b:, "is_kornshell", 0)

Those 3 should probably be instead:

⬇️ Suggested change
-let s:is_kornshell = get(b:, "is_kornshell", 0)
+let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornsh", 0))


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524162901@github.com>

Luca Saccarola

unread,
Dec 27, 2024, 11:30:41 AM12/27/24
to vim/vim, vim-dev ML, Push

@saccarosium pushed 1 commit.

  • 2f06bbe runtime(sh): set shellcheck as the compiler for supported shells

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311/before/1185316b6929dce00142132ac65528338fa1ba73/after/2f06bbec0a898438d6e8de0c9d7293e2889ebd3c@github.com>

Luca Saccarola

unread,
Dec 27, 2024, 11:31:15 AM12/27/24
to vim/vim, vim-dev ML, Comment

@saccarosium commented on this pull request.


In runtime/ftplugin/sh.vim:

> @@ -44,15 +44,21 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
-if get(b:, "is_bash", 0)
+let s:is_sh = get(b:, "is_bash", 0)

Yes, good catch!


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524221031@github.com>

Enno

unread,
Dec 27, 2024, 11:36:48 AM12/27/24
to vim/vim, vim-dev ML, Comment

@saccarosium : Since this is still open, how about falling back to compiler bash if shellcheck not found (and is_bash set ?)


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/c2563857602@github.com>

Luca Saccarola

unread,
Dec 27, 2024, 11:39:13 AM12/27/24
to vim/vim, vim-dev ML, Push

@saccarosium pushed 1 commit.

  • c063cb2 runtime(sh): set shellcheck as the compiler for supported shells

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311/before/2f06bbec0a898438d6e8de0c9d7293e2889ebd3c/after/c063cb2dfae4581ec33219f7d858e1877e70b62c@github.com>

Aliaksei Budavei

unread,
Dec 27, 2024, 3:31:23 PM12/27/24
to vim/vim, vim-dev ML, Comment

@zzzyxwvut commented on this pull request.


In runtime/ftplugin/sh.vim:

> +let s:is_sh = get(b:, "is_sh", 0)
+let s:is_bash = get(b:, "is_bash", 0)
+let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornsh", 0))

Do the introduced s: variables need to stay defined after
the sourcing?

In syntax/sh.vim, there are is_kornshell queries and aren't
is_kornsh ones. Look for is_kornshell with both gets?

In syntax/sh.vim, g:is_sh and g:is_bash are recognised.
Look for these too?


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524367239@github.com>

Aliaksei Budavei

unread,
Dec 27, 2024, 3:31:35 PM12/27/24
to vim/vim, vim-dev ML, Comment

@zzzyxwvut commented on this pull request.


In runtime/ftplugin/sh.vim:

>  
+if executable('shellcheck') && (s:is_sh || s:is_bash || s:is_kornshell)

Test the acquired variables and then do a system call?


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524367311@github.com>

Aliaksei Budavei

unread,
Dec 27, 2024, 3:31:38 PM12/27/24
to vim/vim, vim-dev ML, Comment

@zzzyxwvut commented on this pull request.


In runtime/ftplugin/sh.vim:

>    if !exists('current_compiler')
     compiler shellcheck
   endif
   let b:undo_ftplugin .= ' | compiler make'
+elseif s:isbash
⬇️ Suggested change
-elseif s:isbash
+elseif s:is_bash


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524367352@github.com>

Aliaksei Budavei

unread,
Dec 27, 2024, 3:31:42 PM12/27/24
to vim/vim, vim-dev ML, Comment

@zzzyxwvut commented on this pull request.


In runtime/ftplugin/sh.vim:

> +  if !exists('current_compiler')
+    compiler bash
+  endif
+  let b:undo_ftplugin .= ' | compiler make'
⬇️ Suggested change
-  if !exists('current_compiler')
-    compiler bash
-  endif
-  let b:undo_ftplugin .= ' | compiler make'
+  let b:undo_ftplugin ..= ' | compiler make'

Shouldn't the restoring of compiler be also made conditional
here and at lines 62-65?

There is also an out-of-style use of .= at line 65.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524367392@github.com>

Aliaksei Budavei

unread,
Dec 27, 2024, 3:33:00 PM12/27/24
to vim/vim, vim-dev ML, Comment

Ping the file owner, @dkearns.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/c2564013866@github.com>

Christian Brabandt

unread,
Dec 28, 2024, 4:29:08 AM12/28/24
to vim/vim, vim-dev ML, Comment

@chrisbra commented on this pull request.


In runtime/ftplugin/sh.vim:

> @@ -44,19 +44,30 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
-if get(b:, "is_bash", 0)
+let s:is_sh = get(b:, "is_sh", 0)
⬇️ Suggested change
-let s:is_sh = get(b:, "is_sh", 0)
+let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))

In runtime/ftplugin/sh.vim:

> @@ -44,19 +44,30 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
   let b:undo_ftplugin ..= " | unlet! b:browsefilter"
 endif
 
-if get(b:, "is_bash", 0)
+let s:is_sh = get(b:, "is_sh", 0)
+let s:is_bash = get(b:, "is_bash", 0)
⬇️ Suggested change
-let s:is_bash = get(b:, "is_bash", 0)
+let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524688865@github.com>

Luca Saccarola

unread,
Dec 28, 2024, 12:10:19 PM12/28/24
to vim/vim, vim-dev ML, Push

@saccarosium pushed 1 commit.

  • 5620561 runtime(sh): set shellcheck as the compiler for supported shells

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311/before/c063cb2dfae4581ec33219f7d858e1877e70b62c/after/5620561c0da0d4783586eab2a855f286d5c07b4f@github.com>

Aliaksei Budavei

unread,
Dec 28, 2024, 12:29:37 PM12/28/24
to vim/vim, vim-dev ML, Comment

@zzzyxwvut commented on this pull request.


In runtime/ftplugin/sh.vim:

> +let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))
+let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))
+let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornsh", 0))
⬇️ Suggested change
-let s:is_sh = get(b:, "is_sh", get(g:, "is_sh", 0))
-let s:is_bash = get(b:, "is_bash", get(g:, "is_bash", 0))
-let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornsh", 0))
+let s:is_kornshell = get(b:, "is_kornshell", get(g:, "is_kornshell", 0))

Let me ask again:

Do the introduced s: variables need to stay defined after
the sourcing?

In other words:

unlet s:save_cpo s:is_sh s:is_bash s:is_kornshell


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2524768983@github.com>

Luca Saccarola

unread,
Dec 28, 2024, 1:01:35 PM12/28/24
to vim/vim, vim-dev ML, Push

@saccarosium pushed 1 commit.

  • d117d4d runtime(sh): set shellcheck as the compiler for supported shells

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/16311/before/5620561c0da0d4783586eab2a855f286d5c07b4f/after/d117d4ddcd677fbc08a87d5b8671288e2f207251@github.com>

Christian Brabandt

unread,
Dec 29, 2024, 9:37:58 AM12/29/24
to vim/vim, vim-dev ML, Comment

Closed #16311 via df67fc0.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/issue_event/15780115082@github.com>

Andrea Pappacoda

unread,
Feb 4, 2025, 9:40:33 AM2/4/25
to vim/vim, vim-dev ML, Comment

@Tachi107 commented on this pull request.


In runtime/ftplugin/sh.vim:

>  
+if (s:is_sh || s:is_bash || s:is_kornshell) && executable('shellcheck')

What about is_posix?


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/16311/review/2593081894@github.com>

Reply all
Reply to author
Forward
0 new messages