Skip to content

Commit

Permalink
patch 9.0.1620: Nix files are not recognized from the hashbang line
Browse files Browse the repository at this point in the history
Problem:    Nix files are not recognized from the hashbang line.
Solution:   Add a hashbang check. (issue #12507)
  • Loading branch information
brammool committed Jun 8, 2023
1 parent 85ef2df commit 19548c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions runtime/autoload/dist/script.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ vim9script
# Invoked from "scripts.vim" in 'runtimepath'
#
# Maintainer: Bram Moolenaar <Bram@vim.org>
# Last Change: 2023 May 06
# Last Change: 2023 Jun 08

export def DetectFiletype()
var line1 = getline(1)
Expand Down Expand Up @@ -44,7 +44,7 @@ def DetectFromHashBang(firstline: string)
elseif line1 =~ '^#!\s*[^/\\ ]*\>\([^/\\]\|$\)'
name = substitute(line1, '^#!\s*\([^/\\ ]*\>\).*', '\1', '')
else
name = substitute(line1, '^#!\s*\S*[/\\]\(\i\+\).*', '\1', '')
name = substitute(line1, '^#!\s*\S*[/\\]\(\f\+\).*', '\1', '')
endif

# tcl scripts may have #!/bin/sh in the first line and "exec wish" in the
Expand Down Expand Up @@ -197,6 +197,10 @@ def DetectFromHashBang(firstline: string)
elseif name =~ 'guile'
setl ft=scheme

# Nix
elseif name =~ 'nix-shell'
setl ft=nix

endif
enddef

Expand Down
2 changes: 2 additions & 0 deletions src/testdir/test_filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,7 @@ def s:GetScriptChecks(): dict<list<list<string>>>
expect: [['#!/path/expect']],
gnuplot: [['#!/path/gnuplot']],
make: [['#!/path/make']],
nix: [['#!/path/nix-shell']],
pike: [['#!/path/pike'],
['#!/path/pike0'],
['#!/path/pike9']],
Expand Down Expand Up @@ -902,6 +903,7 @@ def s:GetScriptEnvChecks(): dict<list<list<string>>>
scheme: [['#!/usr/bin/env VAR=val --ignore-environment scheme']],
python: [['#!/usr/bin/env VAR=val -S python -w -T']],
wml: [['#!/usr/bin/env VAR=val --split-string wml']],
nix: [['#!/usr/bin/env nix-shell']],
}
enddef

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1620,
/**/
1619,
/**/
Expand Down

0 comments on commit 19548c6

Please sign in to comment.