New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nix-shell: improve shebang recognition #855
Conversation
Some languages don’t accept shebangs that are more than one line, e.g. lua. This patch laxes the restriction that the second line needs to start with #!, it can now start with any string instead. E.g. in lua one can now use the comment symbols: #!/usr/bin/env nix-shell -- nix-shell -i …
@@ -56,7 +56,7 @@ if ($runEnv && defined $ARGV[0] && $ARGV[0] !~ /nix-shell/) { | |||
@ARGV = (); | |||
while (<SCRIPT>) { | |||
chomp; | |||
if (/^\#\!\s*nix-shell (.*)$/) { | |||
if (/^.*\s*nix-shell (.*)$/) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: .*\s*
-> .*\s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Erm, but then you need a space, don’t you?
That would be quite an arbitrary constraint imho.
I played with the thought of removing \s*
altogether, but I like the explicitness of this version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Actually .*\s*
is equivalent to just .*
. Having \s*
doesn't bring anything to the table since it's part of the .*
set.
cc @edolstra |
Don't think this is a good idea because it will match any line mentioning |
@edolstra You are right, I didn’t look at the surrounding loop very well. |
I think he meant the change is overly permissive. I guess the minimal change would be to add each language individually and so match |
@zimbatm Congratulations on that advanced perlre-fu. If I interpret the loop correctly, this will add any comment line containing the word while (<SCRIPT>) {
chomp;
# #!: normal shebang line, ignored by most programming languages
# (even on the second line)
# --: lua comment
if (/^(?:\#\!|--)\s*nix-shell (.*)$/) {
push @ARGV, shellwords($1);
} else {
last;
}
} |
My knowledge is limited to Regexp unfortunately. Perl is still a bunch of characters to me :) |
I don't know Perl at all, but I'm willing to try! :P while (<SCRIPT> && chomp && /^.*nix-shell (.*)$/) {
push @ARGV, shellwords($1);
} |
Any progress here? |
@olejorgenb Not from my side, no. That kind of slipped through. |
Pretty much out-of-date since |
Some languages don’t accept shebangs that are more than one line, e.g.
lua. This patch laxes the restriction that the second line needs to
start with
#!
, it can now start with any string instead.E.g. in lua one can now use the comment symbols: