-
Notifications
You must be signed in to change notification settings - Fork 405
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
🚀 [syntax highlighting] improved language mappings via shebang #485
Comments
Hi @Kr1ss-XD, the core issue here is that bat has access to the entire file, whereas delta (in its current form) only has access to the section of the file that happens to be in the diff hunk. It would be possible to change delta so that it (optionally) tries to find the file on disk (or from the git repo via libgit2). I have wondered from the beginning whether we would want to do that. Of course, the file might not even exist, since delta simply accepts whatever diff is given to it on stdin, which could be entirely fictional. |
Right, I'm aware that it's not as simple for Since
I haven't considered this though. |
Yes, I agree, this would be possible. And as you say, for things like executable shell scripts, I think it's the only way forwards. |
This would be really nice, @dandavison. ProblemI have a lot of e.g. Python scripts without the
This could be a step that is only run when the filename has no extension at all, so it shouldn't be computationally expensive. You can rely on
SolutionI've created a ZSH script which automatically finds all of the interpreters known to To save you the time of running it, here's the output on my system.
You should be able to add these few bits to |
@dandavison I created a simple solution to this issue, you should be able to use You may want to strip everything after the first comma (e.g. |
Thanks @zachriggle. One thing we should check before proceeding is whether there is a rust crate that already does this and looks to be reliable. Let me know if you're aware of anything. |
@dandavison There is syntect with a relevant function |
Some tools (especially
bat
) check source files for a shebang line and if present use this to assign the according syntax rules. I'm wondering if this would be possible fordelta
, too.Currently, a source file seems to be considered a specific language only if its name/extension can be mapped to a known language. Therefore, generically named files (e.g. executable shell scripts without
*.sh
filename extension) are not being syntax highlighted bydelta
. Considering a shebang could be an option in addition to filenames or--map-syntax
.Maybe it's even possible to use the algorithm/regexes which
bat
has already implemented ?The text was updated successfully, but these errors were encountered: