Skip to content
Snippets Groups Projects
Commit d6d2dff3 authored by healther's avatar healther Committed by scheibelp
Browse files

sbang support: add node-js and fix lua

This adds sbang hook support for node-js and fixes the sbang filter
for lua (the character class exclusion was swallowing newlines and
reporting a false positive if lua was mentioned anywhere in the 
file).
parent 6d155833
No related branches found
No related tags found
No related merge requests found
...@@ -104,6 +104,8 @@ lines=0 ...@@ -104,6 +104,8 @@ lines=0
while read line && ((lines < 2)) ; do while read line && ((lines < 2)) ; do
if [[ "$line" = '#!'* ]]; then if [[ "$line" = '#!'* ]]; then
interpreter="${line#\#!}" interpreter="${line#\#!}"
elif [[ "$line" = '//!'*node* ]]; then
interpreter="${line#//!}"
elif [[ "$line" = '--!'*lua* ]]; then elif [[ "$line" = '--!'*lua* ]]; then
interpreter="${line#--!}" interpreter="${line#--!}"
fi fi
......
...@@ -62,10 +62,17 @@ def filter_shebang(path): ...@@ -62,10 +62,17 @@ def filter_shebang(path):
if original.startswith(new_sbang_line): if original.startswith(new_sbang_line):
return return
# In the following, newlines have to be excluded in the regular expression
# else any mention of "lua" in the document will lead to spurious matches.
# Use --! instead of #! on second line for lua. # Use --! instead of #! on second line for lua.
if re.search(r'^#!(/[^/]*)*lua\b', original): if re.search(r'^#!(/[^/\n]*)*lua\b', original):
original = re.sub(r'^#', '--', original) original = re.sub(r'^#', '--', original)
# Use //! instead of #! on second line for node.js.
if re.search(r'^#!(/[^/\n]*)*node\b', original):
original = re.sub(r'^#', '//', original)
# Change non-writable files to be writable if needed. # Change non-writable files to be writable if needed.
saved_mode = None saved_mode = None
if not os.access(path, os.W_OK): if not os.access(path, os.W_OK):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment