juftin / browsr

🗂️ a pleasant file explorer in your terminal supporting all filesystems
http://juftin.com/browsr/
MIT License
225 stars 13 forks source link

Recognise shebangs #19

Open jalanb opened 1 year ago

jalanb commented 1 year ago

Syntax highlighting seems to br triggered by file types, i.e. file extensions. So that fred.py is highligghted as Python syntax. Unfortunately this means that a file called just fred, which is executable and has #! /usr/bin/env python on the first line is not recognised, hence not highlighted.

juftin commented 1 year ago

Oh this is a good idea. I'm using the rich.syntax.Syntax.guess_lexer method from Rich to handle this currently since the Syntax class is handling almost everything else. In turn it uses pygments to handle it.

https://rich.readthedocs.io/en/stable/reference/syntax.html#rich.syntax.Syntax.guess_lexer https://github.com/juftin/browsr/blob/26a1bf3488916f3c26f96d40c8f33eabee68d358/browsr/browsr.py#L175-L184

I wonder if checking for a shebang would be a welcome addition to the upstream libraries too.