Is there a variant of
cat that outputs syntax-highlighted lines of code when used on a source file?
An idea: maybe
vi[m] or another editor can be asked to dump the syntax-highlighted contents of said files to
stdout and exit immediately?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
Passing the file through
-f terminal will attempt to detect the type from the filename and highlight it appropriately.
The Source-highlight package is shipped with the esc.outlang output language definition, which highlights with ANSI escape sequences.
A handy wrapper
src-hilite-lesspipe.sh is also included in the package, so displaying highlighted output in the terminal is just
src-hilite-lesspipe.sh's primary reason is to help automating the use of
less. You just set:
export LESSOPEN="| /path/to/src-hilite-lesspipe.sh %s" export LESS=' -R '
less source.file will show highlighted source code. (Code in unknown language will pass through unaltered. Highlighting will be also skipped in case of redirected content, like
less < source.file.)
Highlight is simple to use and faster than
It looks good enough for me.