mirror of
				https://github.com/vim/vim.git
				synced 2025-10-28 09:27:14 -04:00 
			
		
		
		
	runtime(sh): consider sh as POSIX shell by default
Also, do not set g:is_kornshell when g:is_posix is set. BSD shells are POSIX but many are derived from the ash shell. closes: #16939 Signed-off-by: Mohamed Akram <mohd.akram@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
		
				
					committed by
					
						 Christian Brabandt
						Christian Brabandt
					
				
			
			
				
	
			
			
			
						parent
						
							5753084042
						
					
				
				
					commit
					51a06ecee0
				
			| @@ -1,4 +1,4 @@ | |||||||
| *syntax.txt*	For Vim version 9.1.  Last change: 2025 Mar 15 | *syntax.txt*	For Vim version 9.1.  Last change: 2025 Mar 21 | ||||||
|  |  | ||||||
|  |  | ||||||
| 		  VIM REFERENCE MANUAL	  by Bram Moolenaar | 		  VIM REFERENCE MANUAL	  by Bram Moolenaar | ||||||
| @@ -3512,25 +3512,25 @@ cases pertain, then the first line of the file is examined (ex. looking for | |||||||
| /bin/sh  /bin/ksh  /bin/bash).  If the first line specifies a shelltype, then | /bin/sh  /bin/ksh  /bin/bash).  If the first line specifies a shelltype, then | ||||||
| that shelltype is used.  However some files (ex. .profile) are known to be | that shelltype is used.  However some files (ex. .profile) are known to be | ||||||
| shell files but the type is not apparent.  Furthermore, on many systems sh is | shell files but the type is not apparent.  Furthermore, on many systems sh is | ||||||
| symbolically linked to "bash" (Linux, Windows+cygwin) or "ksh" (Posix). | symbolically linked to "bash" (Linux, Windows+cygwin) or "ksh" (POSIX). | ||||||
|  |  | ||||||
| One may specify a global default by instantiating one of the following | One may specify a global default by instantiating one of the following | ||||||
| variables in your <.vimrc>: | variables in your <.vimrc>: | ||||||
|  |  | ||||||
|    ksh: > |    ksh: > | ||||||
| 	let g:is_kornshell = 1 | 	let g:is_kornshell = 1 | ||||||
| <   posix:  (using this is nearly the same as setting g:is_kornshell to 1) > | <   posix: (default) > | ||||||
| 	let g:is_posix     = 1 | 	let g:is_posix     = 1 | ||||||
| <   bash: > | <   bash: > | ||||||
| 	let g:is_bash	   = 1 | 	let g:is_bash	   = 1 | ||||||
| <   sh: (default) Bourne shell > | <   dash: > | ||||||
|  | 	let g:is_dash	   = 1 | ||||||
|  | <   sh: Bourne shell > | ||||||
| 	let g:is_sh	   = 1 | 	let g:is_sh	   = 1 | ||||||
|  |  | ||||||
| <   (dash users should use posix) |  | ||||||
|  |  | ||||||
| If there's no "#! ..." line, and the user hasn't availed himself/herself of a | If there's no "#! ..." line, and the user hasn't availed himself/herself of a | ||||||
| default sh.vim syntax setting as just shown, then syntax/sh.vim will assume | default sh.vim syntax setting as just shown, then syntax/sh.vim will assume | ||||||
| the Bourne shell syntax.  No need to quote RFCs or market penetration | the POSIX shell syntax.  No need to quote RFCs or market penetration | ||||||
| statistics in error reports, please -- just select the default version of the | statistics in error reports, please -- just select the default version of the | ||||||
| sh your system uses and install the associated "let..." in your <.vimrc>. | sh your system uses and install the associated "let..." in your <.vimrc>. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ | |||||||
| "		2024 Nov 03 by Aliaksei Budavei <0x000c70 AT gmail DOT com> (improved bracket expressions, #15941) | "		2024 Nov 03 by Aliaksei Budavei <0x000c70 AT gmail DOT com> (improved bracket expressions, #15941) | ||||||
| "		2025 Jan 06 add $PS0 to bashSpecialVariables (#16394) | "		2025 Jan 06 add $PS0 to bashSpecialVariables (#16394) | ||||||
| "		2025 Jan 18 add bash coproc, remove duplicate syn keywords (#16467) | "		2025 Jan 18 add bash coproc, remove duplicate syn keywords (#16467) | ||||||
|  | "		2025 Mar 21 update shell capability detection (#16939) | ||||||
| " Version:		208 | " Version:		208 | ||||||
| " Former URL:		http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH | " Former URL:		http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH | ||||||
| " For options and settings, please use:      :help ft-sh-syntax | " For options and settings, please use:      :help ft-sh-syntax | ||||||
| @@ -17,6 +18,9 @@ if exists("b:current_syntax") | |||||||
|   finish |   finish | ||||||
| endif | endif | ||||||
|  |  | ||||||
|  | " Ensure this is set unless we find another shell | ||||||
|  | let b:is_sh = 1 | ||||||
|  |  | ||||||
| " If the shell script itself specifies which shell to use, use it | " If the shell script itself specifies which shell to use, use it | ||||||
| if getline(1) =~ '\<ksh\>' | if getline(1) =~ '\<ksh\>' | ||||||
|  let b:is_kornshell = 1 |  let b:is_kornshell = 1 | ||||||
| @@ -24,55 +28,45 @@ elseif getline(1) =~ '\<bash\>' | |||||||
|  let b:is_bash      = 1 |  let b:is_bash      = 1 | ||||||
| elseif getline(1) =~ '\<dash\>' | elseif getline(1) =~ '\<dash\>' | ||||||
|  let b:is_dash      = 1 |  let b:is_dash      = 1 | ||||||
| elseif !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh") && !exists("g:is_dash") |  | ||||||
|  " user did not specify which shell to use, and |  | ||||||
|  " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous. |  | ||||||
|  " Assuming /bin/sh is executable, and if its a link, find out what it links to. |  | ||||||
|  let s:shell = "" |  | ||||||
|  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 =~ '\<ksh\>' |  | ||||||
|   let b:is_kornshell= 1 |  | ||||||
|  elseif s:shell =~ '\<bash\>' |  | ||||||
|   let b:is_bash = 1 |  | ||||||
|  elseif s:shell =~ '\<dash\>' |  | ||||||
|   let b:is_dash = 1 |  | ||||||
|  endif |  | ||||||
|  unlet s:shell |  | ||||||
| endif |  | ||||||
|  |  | ||||||
| " handling /bin/sh with is_kornshell/is_sh {{{1 | " handling /bin/sh with is_kornshell/is_sh {{{1 | ||||||
| " b:is_sh will be set when "#! /bin/sh" is found; | " b:is_sh will be set when "#! /bin/sh" is found; | ||||||
| " However, it often is just a masquerade by bash (typically Linux) | " However, it often is just a masquerade by bash (typically Linux) | ||||||
| " or kornshell (typically workstations with Posix "sh"). | " or kornshell (typically workstations with Posix "sh"). | ||||||
| " So, when the user sets "g:is_bash", "g:is_kornshell", | " So, when the user sets "g:is_kornshell", "g:is_bash", | ||||||
| " or "g:is_posix", a b:is_sh is converted into b:is_bash/b:is_kornshell, | " "g:is_posix" or "g:is_dash", a b:is_sh is converted into | ||||||
| " respectively. | " b:is_kornshell/b:is_bash/b:is_posix/b:is_dash, respectively. | ||||||
| if !exists("b:is_kornshell") && !exists("b:is_bash") && !exists("b:is_dash") | elseif !exists("b:is_kornshell") && !exists("b:is_bash") && !exists("b:is_posix") && !exists("b:is_dash") | ||||||
|   if exists("g:is_posix") && !exists("g:is_kornshell") |  if exists("g:is_kornshell") | ||||||
|    let g:is_kornshell= g:is_posix |   let b:is_kornshell= 1 | ||||||
|  |  elseif exists("g:is_bash") | ||||||
|  |   let b:is_bash= 1 | ||||||
|  |  elseif exists("g:is_dash") | ||||||
|  |   let b:is_dash= 1 | ||||||
|  |  elseif exists("g:is_posix") | ||||||
|  |   let b:is_posix= 1 | ||||||
|  |  elseif exists("g:is_sh") | ||||||
|  |   let b:is_sh= 1 | ||||||
|  |  else | ||||||
|  |   " user did not specify which shell to use, and | ||||||
|  |   " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous. | ||||||
|  |   " Assuming /bin/sh is executable, and if its a link, find out what it links to. | ||||||
|  |   let s:shell = "" | ||||||
|  |   if executable("/bin/sh") | ||||||
|  |    let s:shell = resolve("/bin/sh") | ||||||
|  |   elseif executable("/usr/bin/sh") | ||||||
|  |    let s:shell = resolve("/usr/bin/sh") | ||||||
|   endif |   endif | ||||||
|   if exists("g:is_kornshell") |   if     s:shell =~ '\<ksh\>' | ||||||
|     let b:is_kornshell= 1 |    let b:is_kornshell= 1 | ||||||
|     if exists("b:is_sh") |   elseif s:shell =~ '\<bash\>' | ||||||
|       unlet b:is_sh |    let b:is_bash = 1 | ||||||
|     endif |   elseif s:shell =~ '\<dash\>' | ||||||
|   elseif exists("g:is_bash") |    let b:is_dash = 1 | ||||||
|     let b:is_bash= 1 |  | ||||||
|     if exists("b:is_sh") |  | ||||||
|       unlet b:is_sh |  | ||||||
|     endif |  | ||||||
|   elseif exists("g:is_dash") |  | ||||||
|     let b:is_dash= 1 |  | ||||||
|     if exists("b:is_sh") |  | ||||||
|       unlet b:is_sh |  | ||||||
|     endif |  | ||||||
|   else |   else | ||||||
|     let b:is_sh= 1 |    let b:is_posix = 1 | ||||||
|   endif |   endif | ||||||
|  |   unlet s:shell | ||||||
|  |  endif | ||||||
| endif | endif | ||||||
|  |  | ||||||
| " if b:is_dash, set b:is_posix too | " if b:is_dash, set b:is_posix too | ||||||
| @@ -80,6 +74,12 @@ if exists("b:is_dash") | |||||||
|  let b:is_posix= 1 |  let b:is_posix= 1 | ||||||
| endif | endif | ||||||
|  |  | ||||||
|  | if exists("b:is_kornshell") || exists("b:is_bash") | ||||||
|  |  if exists("b:is_sh") | ||||||
|  |   unlet b:is_sh | ||||||
|  |  endif | ||||||
|  | endif | ||||||
|  |  | ||||||
| " set up default g:sh_fold_enabled {{{1 | " set up default g:sh_fold_enabled {{{1 | ||||||
| " ================================ | " ================================ | ||||||
| if !exists("g:sh_fold_enabled") | if !exists("g:sh_fold_enabled") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user