Sublime Forum

Sublime Syntax Highlighting for the Commandline

#1

Hi! I’ve created a command-line tool that is capable of applying syntax highlighting to piped input and supports (work in progress) both sublime-syntax and sublime-color-scheme formats, so for example cat source.c | python3 hl.py -s C -c Celeste would apply the C language syntax highlighting using the Celeste color-scheme to the output of cat source.c.
I find it very useful, above all when combined with a custom syntax applied for example to logs.
I thought it would be cool to share it with the community. You can find the source code at https://github.com/sublhighlight/sublhighlight.
Please, leave some feedback or open an issue or a PR.
Hope you’ll enjoy!

1 Like

#2

Thanks for sharing - looks interesting! I might be tempted to add some unit tests and support for syntax test files so we can check the correctness :slightly_smiling_face:

0 Likes

#3

Fwiw, this is my cat :cat: and this is bat :bat:, which uses Sublime Text’s syntax definition v1 I believe or partially v2 maybe (I know it’s syntax engine doesn’t support branch yet). Oh I see keith-hall is there.

alias cat='bat -pp --paging=never --style=plain --theme="Monokai Extended Origin"'
0 Likes

#4

Cool, didn’t know about that, thank you

0 Likes

#5

That would be great actually, I’m pretty much sure it would uncover some problems!
Syntax test files! I knew there must have been a way to test it, more info please!

0 Likes

#6

https://www.sublimetext.com/docs/syntax.html#testing
There’s a Rust implementation here: https://github.com/trishume/syntect/blob/master/examples/syntest.rs

0 Likes

#7

thank you, did skim over that too quickly to realise what it was actually saying.

0 Likes