]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1342: Shebang filetype detection can be improved v9.1.1342
authorEisuke Kawashima <e-kwsm@users.noreply.github.com>
Thu, 24 Apr 2025 20:03:21 +0000 (22:03 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 24 Apr 2025 20:03:21 +0000 (22:03 +0200)
Problem:  Shebang filetype detection can be improved
Solution: Improve detection logic (Eisuke Kawashima)

Vim does not correctly detect filetype from
  - `#!/usr/bin/env --split-string=awk -f`
  - `#!/usr/bin/env -S -i awk -f`
  - `#!/usr/bin/env -S VAR= awk -f`
So update the current detection logic to detect those cases.

closes: #17199

Signed-off-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/autoload/dist/script.vim
src/testdir/test_filetype.vim
src/version.c

index 859126f0f6370d963fbb8e390944c48979cd6bd4..c184bd032d3ccafb3d78de23af0297b3bf5d7d85 100644 (file)
@@ -4,7 +4,7 @@ vim9script
 # Invoked from "scripts.vim" in 'runtimepath'
 #
 # Maintainer:  The Vim Project <https://github.com/vim/vim>
-# Last Change: 2025 Jan 20
+# Last Change: 2025 Apr 24
 # Former Maintainer:   Bram Moolenaar <Bram@vim.org>
 
 export def DetectFiletype()
@@ -26,8 +26,9 @@ def DetectFromHashBang(firstline: string)
   # "#!/usr/bin/bash" to make matching easier.
   # Recognize only a few {options} that are commonly used.
   if line1 =~ '^#!\s*\S*\<env\s'
-    line1 = substitute(line1, '\S\+=\S\+', '', 'g')
-    line1 = substitute(line1, '\(-[iS]\|--ignore-environment\|--split-string\)', '', '')
+    line1 = substitute(line1, '\s\zs--split-string[ \t=]', '', '')
+    line1 = substitute(line1, '\s\zs[A-Za-z0-9_]\+=\S*\ze\s', '', 'g')
+    line1 = substitute(line1, '\s\zs\%(-[iS]\+\|--ignore-environment\)\ze\s', '', 'g')
     line1 = substitute(line1, '\<env\s\+', '', '')
   endif
 
index a7bb8bf7da29626a1d51351c60fd3f3643225447..dc653f5b44206b8a6bddb908cefcf1db956af1f2 100644 (file)
@@ -1073,10 +1073,10 @@ def s:GetScriptEnvChecks(): dict<list<list<string>>>
   return {
     perl: [['#!/usr/bin/env VAR=val perl']],
     scala: [['#!/usr/bin/env VAR=val VVAR=vval scala']],
-    awk: [['#!/usr/bin/env VAR=val -i awk']],
+    awk: [['#!/usr/bin/env --split-string=VAR= awk -vFS="," -f']],
     execline: [['#!/usr/bin/env execlineb']],
     scheme: [['#!/usr/bin/env VAR=val --ignore-environment scheme']],
-    python: [['#!/usr/bin/env VAR=val -S python -w -T']],
+    python: [['#!/usr/bin/env -S -i VAR=val python -B -u']],
     wml: [['#!/usr/bin/env VAR=val --split-string wml']],
     nix: [['#!/usr/bin/env nix-shell']],
   }
index 8d881242f60c06f7fc4f4ee408dd3a9a0d3d8022..a07561eb6d745399b4e6f86cc632e8348350d214 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1342,
 /**/
     1341,
 /**/