77" 2024 Nov 03 by Aliaksei Budavei <0x000c70 AT gmail DOT com> (improved bracket expressions, #15941)
88" 2025 Jan 06 add $PS0 to bashSpecialVariables (#16394)
99" 2025 Jan 18 add bash coproc, remove duplicate syn keywords (#16467)
10+ " 2025 Mar 21 update shell capability detection (#16939)
1011" Version: 208
1112" Former URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH
1213" For options and settings, please use: :help ft-sh-syntax
@@ -17,69 +18,68 @@ if exists("b:current_syntax")
1718 finish
1819endif
1920
21+ " Ensure this is set unless we find another shell
22+ let b: is_sh = 1
23+
2024" If the shell script itself specifies which shell to use, use it
2125if getline (1 ) = ~ ' \<ksh\>'
2226 let b: is_kornshell = 1
2327elseif getline (1 ) = ~ ' \<bash\>'
2428 let b: is_bash = 1
2529elseif getline (1 ) = ~ ' \<dash\>'
2630 let b: is_dash = 1
27- elseif ! exists (" g:is_kornshell" ) && ! exists (" g:is_bash" ) && ! exists (" g:is_posix" ) && ! exists (" g:is_sh" ) && ! exists (" g:is_dash" )
28- " user did not specify which shell to use, and
29- " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous.
30- " Assuming /bin/sh is executable, and if its a link, find out what it links to.
31- let s: shell = " "
32- if executable (" /bin/sh" )
33- let s: shell = resolve (" /bin/sh" )
34- elseif executable (" /usr/bin/sh" )
35- let s: shell = resolve (" /usr/bin/sh" )
36- endif
37- if s: shell = ~ ' \<ksh\>'
38- let b: is_kornshell= 1
39- elseif s: shell = ~ ' \<bash\>'
40- let b: is_bash = 1
41- elseif s: shell = ~ ' \<dash\>'
42- let b: is_dash = 1
43- endif
44- unlet s: shell
45- endif
46-
4731" handling /bin/sh with is_kornshell/is_sh {{{1
4832" b:is_sh will be set when "#! /bin/sh" is found;
4933" However, it often is just a masquerade by bash (typically Linux)
5034" or kornshell (typically workstations with Posix "sh").
51- " So, when the user sets "g:is_bash", "g:is_kornshell",
52- " or "g:is_posix", a b:is_sh is converted into b:is_bash/b:is_kornshell,
53- " respectively.
54- if ! exists (" b:is_kornshell" ) && ! exists (" b:is_bash" ) && ! exists (" b:is_dash" )
55- if exists (" g:is_posix" ) && ! exists (" g:is_kornshell" )
56- let g: is_kornshell= g: is_posix
35+ " So, when the user sets "g:is_kornshell", "g:is_bash",
36+ " "g:is_posix" or "g:is_dash", a b:is_sh is converted into
37+ " b:is_kornshell/b:is_bash/b:is_posix/b:is_dash, respectively.
38+ elseif ! exists (" b:is_kornshell" ) && ! exists (" b:is_bash" ) && ! exists (" b:is_posix" ) && ! exists (" b:is_dash" )
39+ if exists (" g:is_kornshell" )
40+ let b: is_kornshell= 1
41+ elseif exists (" g:is_bash" )
42+ let b: is_bash= 1
43+ elseif exists (" g:is_dash" )
44+ let b: is_dash= 1
45+ elseif exists (" g:is_posix" )
46+ let b: is_posix= 1
47+ elseif exists (" g:is_sh" )
48+ let b: is_sh= 1
49+ else
50+ " user did not specify which shell to use, and
51+ " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous.
52+ " Assuming /bin/sh is executable, and if its a link, find out what it links to.
53+ let s: shell = " "
54+ if executable (" /bin/sh" )
55+ let s: shell = resolve (" /bin/sh" )
56+ elseif executable (" /usr/bin/sh" )
57+ let s: shell = resolve (" /usr/bin/sh" )
5758 endif
58- if exists (" g:is_kornshell" )
59- let b: is_kornshell= 1
60- if exists (" b:is_sh" )
61- unlet b: is_sh
62- endif
63- elseif exists (" g:is_bash" )
64- let b: is_bash= 1
65- if exists (" b:is_sh" )
66- unlet b: is_sh
67- endif
68- elseif exists (" g:is_dash" )
69- let b: is_dash= 1
70- if exists (" b:is_sh" )
71- unlet b: is_sh
72- endif
59+ if s: shell = ~ ' \<ksh\>'
60+ let b: is_kornshell= 1
61+ elseif s: shell = ~ ' \<bash\>'
62+ let b: is_bash = 1
63+ elseif s: shell = ~ ' \<dash\>'
64+ let b: is_dash = 1
7365 else
74- let b: is_sh = 1
66+ let b: is_posix = 1
7567 endif
68+ unlet s: shell
69+ endif
7670endif
7771
7872" if b:is_dash, set b:is_posix too
7973if exists (" b:is_dash" )
8074 let b: is_posix= 1
8175endif
8276
77+ if exists (" b:is_kornshell" ) || exists (" b:is_bash" )
78+ if exists (" b:is_sh" )
79+ unlet b: is_sh
80+ endif
81+ endif
82+
8383" set up default g:sh_fold_enabled {{{1
8484" ================================
8585if ! exists (" g:sh_fold_enabled" )
0 commit comments