-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Prioritize shebang if no file extension is provided #5869
Comments
In general Helix checks for the shebang if it can't find a We could change the form expected for full filenames to something similar to what we use for suffix file-types (see https://docs.helix-editor.com/master/languages.html#file-type-detection-and-the-file-types-key) [[language]]
name = "ruby"
file-types = [{ filename = "Rakefile" }, "rb"] but this would be a breaking change for languages.toml configuration. |
Thank you very much for your detailed answer!
I cope well von one of the posted solutions; but I cannot judge whether a breaking change is justified ;-) Please give me a hint if you want me to close this issue. Thanks a lot! |
I'll leave this open and add some tags to it. Since there's a workaround (the languages.toml snippet) and it's unlikely to occur most of the time, I don't think it's worth making the breaking change to configuration for now. Eventually we want to replace the TOML configuration with something more powerful and we might be able to use that change as an opportunity to clean up some config options that need to be tweaked like this. |
One option would be to change the format to:
And then anything that isn't a struct is legacy compat. |
This way each string is explicitly listed as a filename/extension/suffix, unlike the current format where strings like
|
I just hit this with a shell script named |
I think syntax highlighting based on filenames is frequent enough to be a valid consideration:
I'm personally in favor for this breaking change, in a format similar to what @Plasma-Vortex suggested. I think Shebangs should take priority, followed by path suffixes, filenames and then extensions:
ImplementationI got the filenames in the first table from a YAML file maintained by Github: Shell:
type: programming
color: "#89e051"
aliases:
- sh
- shell-script
- bash
- zsh
extensions:
- ".sh"
- ".bash"
- ".bats"
- ".cgi"
...
filenames:
- ".bash_aliases"
- ".bash_history"
- ".bash_logout"
- ".bash_profile"
- ".bashrc"
...
interpreters:
- ash
- bash
- dash
...
tm_scope: source.shell
ace_mode: sh
codemirror_mode: shell
codemirror_mime_type: text/x-sh
language_id: 346 We can use these to help us write the default configuration file. Hopefully, the defaults will be rich enough that most users won't have to touch the configuration files at all. I don't see this upgrade being an issue for end users, I think this is a relatively self-explanatory scheme to migrate to. |
I changed my mind after running into this issue myself (with a file named I still think we should use the format described above, Edit: Unfortunately I don't have the bandwidth to work on this. But if anyone wants to submit a PR for this, go ahead! |
Just wanted to mention that this merged pull request(?) seems to have solved my initial issue. EDIT: O sorry. I posted rubbish. I just forget about my workarounds. Still an issue. Sorry, guys! |
I agree that shebangs should always be preferred over file-types. My issue is with |
I don't see any mention of offering an explicit override as a file comment header, like other editors support for various things, not only to set the language. Perhaps have some generic form of executing a subset of commands that are flagged as safe, using the synax Parsing comments until the first non-blank non-comment line, this could look like: # Example file with some license or what-not nonsense
# at the top.
# helix:lang bash
# Or for custom options in this particular file:
# helix:set search.smart-case false
exec ... |
Hi!
In my
bin
folder there are some single letter POSIX/Bash executables:c
(calendar),p
(password script) andf
(fuzzy finder).Although the correct shebangs are provided (
#!/usr/bin/[sh,bash]
) Helix recognizes the files’ languages asc
,perl
andfortran
.It is easy to solve this problem, e.g. by renaming the files and using the shells abbreviations or aliases, by adding
[.sh,.bash]
file extensions or by addingfile-types
tolanguales.toml
like this:I just wanted to mention this in case it is a Helix issue.
Should helix generelly prioritize the shegang if no file extension is provided?
Thanks a lot!
The text was updated successfully, but these errors were encountered: