sbarex / SourceCodeSyntaxHighlight

Quick Look extension for highlight source code files on macOS 10.15 and later.
GNU General Public License v3.0
2.88k stars 72 forks source link

Source code language is not detected for files using a shebang (and not a file extension) #224

Open murdock-grewar opened 1 year ago

murdock-grewar commented 1 year ago

This quick-look extension (SourceCodeSyntaxHighlight) does not detect the syntax/language of files which use shebangs and not file extensions.

For source code of interpreted languages, it is standard practice to create executable files containing a so-called "shebang" comment line which dictates which executable should be used to interpret the code.

(I think the way it works is that files beginning with a shebang line are opened with the system's default shell, and the shell then runs the executable specified in the shebang, with the source code filepath as the first argument. Something like this.)

This quick-look extension should appropriately highlight the syntax of such files. It is standard practice to write executable files this way; the file extension is there for convenience, not because it is strictly necessary. Such files are added to the $PATH of the system's shell, and therefore become executables which can be called by name. And usually we do not want unnecessary file extensions inside an executable name. The shebang line tells the shell which program to use to interpret the source code.

Here is an example of a source file which is not syntax-highlighted by this quick-look extension:

Screenshot 2023-01-22 at 17 07 42

Here is what it should look like instead (I triggered the syntax highlighting by renaming the file from "newpy" to "newpy.sh"):

Screenshot 2023-01-22 at 17 08 12

I am aware of two variants of shebangs:

  1. #!/path/to/executable
  2. #!/usr/bin/env executable Though there are other ways to use shebangs, these are by far the most common, I believe, and both should be handled by this quick-look extension.
sbarex commented 3 months ago

For now the app do not parse the shebang header.