color cat - cat(1) with regex-based syntax highlighting.
 
 
 
Go to file
Aadhavan Srinivasan a1309af696 Updated some regexes
One of the expressions used .* to mean 'any character except newline', but since I've
enabled 'RE_SINGLE_LINE' mode, a dot matches a newline as well.
config Updated some regexes
stack First commit
.gitignore Updated gitignore
LICENSE.md Added license
Makefile First commit
README.md Updated README and TODO
color.go Added SGR fields to the RGB struct for bold and italic;
colorunit.go Replaced 'panic' with an error return, and a call to 'printAndExit'
config.go Enable RE_SINGLE_LINE flag when compiling regex, to allow newline to be treated like any other character
create_release_builds.sh Removed references to Windows support
errors.go Renamed 'printAndExit' to 'printErrAndExit'
go.mod Use my regex engine instead of the stdlib one
go.sum Use my regex engine instead of the stdlib one
main.go Use my regex engine instead of the stdlib one
regcolor.go Use my regex engine instead of the stdlib one
todo.txt Updated README and TODO
vision.txt First commit

README.md

ccat

ccat is a file printing tool (like 'cat') which uses Regular Expressions to enable syntax highlighting.


Features

  • 11 colors are defined out-of-the-box: RED, BLUE, GREEN, MAGENTA, CYAN, BLACK, WHITE, YELLOW, GRAY, ORANGE and DARKBLUE.
  • Support for defining custom colors via the ccat.colors file.
  • Regex-color mappings are stored in configuration files.
  • Uses the file extension to determine which configuration file to use.
  • Highly extensible - to add a config file for an specific file type, name the file <extension>.conf.
  • Support for printing line numbers with the -n flag.
  • Statically linked Go binary - no runtime dependencies, config files are distributed along with the binary.
  • Linux and MacOS supported.

Installing

Download the appropriate zip-file from the 'Releases' section. Place the executable in your PATH.

NOTE: The releases are not available on the GitHub repo (which is a mirror of https://gitea.twomorecents.org/Rockingcool/ccat). Obtain the releases from there instead.


Building from source

If you have the go command installed, run make after cloning the repository.


Supported Languages

The following languages have config files included by default:

  • C
  • Go

Getting Started

The config files are embedded within the binary. They will automatically be installed to the correct location (~/.config/ccat on UNIX) when the program is first run.

As written above, if provided a file with extension .example, the program will look for the config file named example.conf. If such a file doesn't exist, the file is printed out without any highlighting.

For example, if you want to create syntax highlighting for Java, create a file named java.conf in your config directory. In this file, include regular-expressions for each of the langauges's keywords, and provide a corresponding color. Use the provided c.conf and go.conf files as a starting point.


Config Files

The config files are written in YAML. Each line has the following syntax:

"<regex>": COLOR

Note that the regex must be enclosed in double quotes, and the color must be capitalized.


Custom Colors

To define a color of your own, create a file named ccat.colors in the config directory (mentioned above). The syntax of this file is the following:

COLOR: <red> <green> <blue>

Note that the color name must be capitalized (and shouldn't contain spaces). The RGB values must each be from 0 to 255.


TODO:

  • Windows support.
  • Allow users to provide a config file in the command-line, overriding the extension-based config file.