Hi Charles,

Given this shell script

  #!/bin/sh
  echo ${FOO#bar}

the # is highlighted as an error when /bin/sh is provided by dash.  This
is a similar issue to one I had reported before with process
substitution.

That was fixed by adding an '|| exists("b:is_posix")' check before
defining shCommandSub.  The attached sh.vim-param.diff implements a
similar fix for shDerefOp.

However, I wonder if there's a better fix for these issues.  They were
introduced by the sh.vim update from v147 to v151 
(https://github.com/vim/vim/commit/91c4937be15b0b743b6bc495df602c1abbff6b87#diff-3684eb3d10603a1e201bf60108720b02).

Prior to that sh.vim update, the g:is_* variables would be set based on
the detected shell (g:is_posix for dash).  After that, the buffer-local
variables would be set, which would result in b:is_kornshell being set.

  if executable("/bin/sh")
   let s:shell = resolve("/bin/sh")
  elseif executable("/usr/bin/sh")
   let s:shell = resolve("/usr/bin/sh")
  endif
  if     s:shell =~ 'bash$'
   let g:is_bash= 1
  elseif s:shell =~ 'ksh$'
   let g:is_kornshell = 1
  elseif s:shell =~ 'dash$'
   let g:is_posix = 1
  endif
  ...
  if !exists("b:is_kornshell") && !exists("b:is_bash")
   if exists("g:is_posix") && !exists("g:is_kornshell")
    let g:is_kornshell= g:is_posix
   endif

After that sh.vim update, b:is_posix is set when dash is detected, which
bypasses the g:is_* variable -> buffer-local conversion, so now dash is
operating with b:is_posix and b:is_sh set instead of b:is_kornshell.

Would it be better to revert that part of the sh.vim update or possibly
set both b:is_kornshell and b:is_posix for dash?  Then ksh specific code
could check for is_kornshell and !is_posix.

Cheers,
-- 
James
GPG Key: 4096R/91BF BF4D 6956 BD5D F7B7  2D23 DFE6 91AE 331B A3DB
diff --git i/runtime/syntax/sh.vim w/runtime/syntax/sh.vim
index 838c5eb4a..89d45869d 100644
--- i/runtime/syntax/sh.vim
+++ w/runtime/syntax/sh.vim
@@ -490,7 +490,7 @@ if !exists("g:sh_no_error")
 endif
 syn match  shDerefOp	contained	":\=[-=?]"	nextgroup=@shDerefPatternList
 syn match  shDerefOp	contained	":\=+"	nextgroup=@shDerefPatternList
-if exists("b:is_bash") || exists("b:is_kornshell")
+if exists("b:is_bash") || exists("b:is_kornshell") || exists('b:is_posix')
  syn match  shDerefOp	contained	"#\{1,2}"		nextgroup=@shDerefPatternList
  syn match  shDerefOp	contained	"%\{1,2}"		nextgroup=@shDerefPatternList
  syn match  shDerefPattern	contained	"[^{}]\+"		contains=shDeref,shDerefSimple,shDerefPattern,shDerefString,shCommandSub,shDerefEscape nextgroup=shDerefPattern

Reply via email to