mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
vim-patch:9.1.1342: Shebang filetype detection can be improved
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: vim/vim#17199
f102f4c2e8
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
This commit is contained in:
@ -1959,11 +1959,10 @@ local function match_from_hashbang(contents, path, dispatch_extension)
|
||||
-- "#!/usr/bin/bash" to make matching easier.
|
||||
-- Recognize only a few {options} that are commonly used.
|
||||
if matchregex(first_line, [[^#!\s*\S*\<env\s]]) then
|
||||
first_line = first_line:gsub('%S+=%S+', '')
|
||||
first_line = first_line
|
||||
:gsub('%-%-ignore%-environment', '', 1)
|
||||
:gsub('%-%-split%-string', '', 1)
|
||||
:gsub('%-[iS]', '', 1)
|
||||
first_line = fn.substitute(first_line, [[\s\zs--split-string\(\s\|=\)]], '', '')
|
||||
first_line = fn.substitute(first_line, [[\s\zs[A-Za-z0-9_]\+=\S*\ze\s]], '', 'g')
|
||||
first_line =
|
||||
fn.substitute(first_line, [[\s\zs\%(-[iS]\+\|--ignore-environment\)\ze\s]], '', 'g')
|
||||
first_line = fn.substitute(first_line, [[\<env\s\+]], '', '')
|
||||
end
|
||||
|
||||
|
@ -1068,10 +1068,10 @@ func s:GetScriptEnvChecks() abort
|
||||
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']],
|
||||
\ }
|
||||
|
Reference in New Issue
Block a user