Syntax highlighting for extension-less files
If a file has no extension (like nginx config files), then no syntax highlighting will be given.
My suggestion is to add support for picking the language that Chroma is using for syntax highlighting. This has the added benefit that if a file extension is not correct (like a .log file with json content), then the user can pick the correct language and have syntax highlighting.
BTW, thanks for the awesome tool! I found it to be the best pager out there!
Is this what you're after?
cat build.sh | moar --lang=shell
If so, it's already in there :)
I assume you ran into this when viewing some particular file.
What was the name of that file, and what kind of file was it?
OP stated it was an nginx-config file.
Mine is a bash shell file I wrote without the .sh extension. (The name of the file is load-zellij shebang is #! /usr/bin/env bash)
@Shayan-To, what command are you using to have Chroma pick the language to use for syntax highlighting?
moar currently uses Chroma's identify-by-file-name functionality, but not Chroma's identify-by-contents functionality.
Sorry to reply so late.
I think it's not really practical to use the --lang argument, as one needs to memorize or check the list of supported languages every time. An interactive option would be more practical, like pressing a key from within moar, and selecting the language from a list.
Detecting the shebang (or other ways of detection) would also be very very helpful, as it will solve a lot of the cases without any need for manual input. (Although it wouldn't work for nginx config files, that I think would require manual input anyway.)
@Shayan-To what's the full path to that nginx config file on your machine? I want to see if I can do better regarding figuring out the file type based on its path.
On Linux, the standard directory for Nginx config files is /etc/nginx. The config files have different contexts, but the syntax seems like to be the same.
On Windows though, there is no standard path (as it is portable and can be placed anywhere), but it usually ends with nginx-VERSION/conf/*.
Is the interactive language selection a difficult feature to implement? I think it would be a very useful feature. I use the language selection feature of VSCode all the time (so much I have assigned a hot key for it), and have wished for a similar feature in moar many times when syntax highlighting was not available.
Is the interactive language selection a difficult feature to implement?
Somewhat, yes.
Something that would be a lot easier might be to ensure your nginx config files get detected properly when you open them in moar on your system.
So on your system, where you sometimes view nginx config files in moar, what is the exact path to one of these nginx config files?
These are the usual nginx config files:
/etc/nginx/conf.d/*.conf
/etc/nginx/modules-available/*.conf
/etc/nginx/modules-enabled/*.conf
/etc/nginx/nginx.conf
/etc/nginx/sites-available/*
/etc/nginx/sites-enabled/*
/etc/nginx/snippets/*.conf
Although I have other files inside /etc/nginx (so for me, /etc/nginx/* is also on the list).
I think all the files inside /etc/nginx have the same general syntax, so /etc/nginx/** might be good as well.
Given this information I would say that these two patterns should cover the files on your system:
nginx.confnginx/*/*.conf
The current pattern is just nginx.conf:
https://github.com/alecthomas/chroma/blob/b3104143efa8799cb956dda26c1bb637d695fc97/lexers/embedded/nginx_configuration_file.xml#L2-L7
Wanna make a PR for Chroma? I believe the XML format accepts multiple <filename> entries. If you do, post a link here!
nginx.conf
nginx/*/*.conf
This is not totally correct. Config files inside /etc/nginx/sites-available and /etc/nginx/sites-enabled do not usually have .conf extension (as they are not config files). And for my own setup, I have other files inside /etc/nginx that are not "config" files and so do not have .conf extension.
When you say that certain files are not "config" files, what does that mean?
Are those files not in nginx config file format?
Way back, on Apache, sites-enabled and sites-available contained symlinks to config files. I don't remember their extensions, but opening one of those gave you a text that should have been highlighted.