-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add support for #!/usr/bin/env nix-shell #1210
Comments
I don't know much about nix-shell, from [0], it seems like it downloads nix deps and opens a bash shell, so will it be okay to treat the file as bash? |
What the file is supposed to contain depends on the This is an example of correct usage:
The |
|
Can we get some feedback from whoever maintains this that this is a feature that would be accepted? |
I am very hesitant to add first-class support for new shells, because it's easy to add but hard to maintain and remove. I'd prefer a simple third party wrapper script nix-shellcheck that invokes |
@koalaman Thanks for your reply. I don't know what you mean by first-class support for new shells in this particular case. The only thing that needs to happen is a conditional to check for the first line being equal to and in that case, it should look for the I don't understand your concerns. |
@coretemp Would the shell directive be useful in this case? |
The shell directive does solve this issue for me! Thanks @qubidt. I just wanted to share an example of how to use it here for the next person stumbling upon this issue: $ cat test-shell.sh
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p hello
#shellcheck shell=bash
hello
$ ./test-shell.sh
Hello, world!
$ shellcheck test-shell.sh
$ echo $?
0 |
I would really love to see shellcheck gain native support for this, so I don't end up with errors in VS Code every time I edit a shell script that uses nix-shell. In my own scripts I can add shell directives, but I'm often opening scripts I don't control. |
Agree with @lilyball, if a PR implementing support for this (identifying the |
@expipiplus1 Sure, it makes sense for autoidentifying purpose |
Great, it looks like it would require a slight change to the parser to not ignore additional "shebang"s at the top of the file, at the moment the pretend |
There's an open issue about teaching shellcheck to automatically recognize nix-shell shebangs: koalaman/shellcheck#1210 Signed-off-by: Alyssa Ross <alyssa.ross@unikie.com> Message-Id: <20221118100947.33597-1-alyssa.ross@unikie.com>
This is not a nix-shell specific bug. Effectively it does the same as something like: Uses:
Ref: |
Shellcheck already supports |
Hmm, well when running in vscode it seems to disagree, at least for me.... Could it be that the vscode plugin that uses this project is somehow disabling this feature? (Shellcheck/VSCode wrapper v0.34.0) Note the debug console states that it is using the latest 0.9.0 shellcheck binary. |
That's because you're using |
Interesting, you are right, the error goes away if I remove the explicit path to the interpreter. (BTW as I am not allowed to post my actual scripts here I made a cut and paste error in the empty file that I snipped the error from, in doing that I omitted the leading /) As we all know, despite age, there are still things to learn.... It has always been my take that without an explicit path I am at the mercy of whatever path the requested interpreter is found at (note, I am on a huge system with ~10k+ users and make use of gnu environemt modules), so without being explicit, surely it could be dangerous? e.g. a user could accidently (or deliberately) insert line into their own path and use an interpreter that behaved differently to the intended one? |
Well wrong might be a strong word here, considering it still works. Let's check
You are correct that by ommiting the path you're at the mercy of
Mixing |
The fact that |
For new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
Empty output, because it's a standard way of using nix-shell.
The text was updated successfully, but these errors were encountered: