jpe90/clp

writes input files to stdout with syntax highlighting

97

stars

72

commits

Lua

primary language

Feb 4, 2026

updated

README

clp

clp writes input files to stdout with syntax highlighting. It aims to be relatively fast, provide wide language support, and be easy to extend with new languages. It currently supports 150 languages.

clpm

Language support is implemented with LPEG, a tool developed by PUC which uses parsing expression grammars to improve upon traditional regex parsers (described in depth in this article).

More information is available here, along with a blog post showing how I use it with fzf.

Installation

MacOS

brew tap jpe90/clp
brew install jpe90/clp/clp

Linux

AUR

Building from source

Requirements:

  • a POSIX compliant operating system
  • a C99 Compiler
  • Lua >= 5.1 or LuaJIT (the latter for better performance)
  • LPEG
  • luautf8
$ ./configure
$ make
# make install

Distro Specific Dependencies

Ubuntu
# apt-get install -y build-essential pkg-config libluajit-5.1-dev lua-lpeg
# luarocks --lua-version=5.1 install luautf8
Arch
# pacman -S --needed --noconfirm base-devel pkg-config luajit lua51-lpeg lua51-luautf8

Usage

$ clp [options] filename

Convenience script (example)

An example helper script is included at scripts/sp. It uses rg + fzf and previews with clp. This is only an example, and it opens files with Neovim (nvim) on ctrl-o. Adjust it to your editor and workflow as needed.

-t, --override-filetype {filetype}

Force a language's syntax for highlighting the file. To see available filetypes, run clp --list-overrides

-h, --highlight-line {number}

Highlight a non-blank line

Motivation

Existing syntax highlighting programs are either relatively slow or support a small number of languages. clp aims to be faster without compromising on language support.

Here are some quick benchmarks comparing similar programs running on my machine (clp installed with LuaJIT, highlighting sqlite3.c)

CommandMean [ms]Min [ms]Max [ms]Relative
clp sqlite3.c216.6 ± 2.4212.2220.81.00
bat --color=always sqlite3.c3161.0 ± 12.33149.73182.714.59 ± 0.17
source-highlight sqlite3.c4313.6 ± 25.54277.74355.919.91 ± 0.25

More benchmarks are available here

Parsers are upstreamed from the Scintillua project. It's actively maintained, has great support even for niche languages, and easy to use relative to other syntax definition mechanisms.

Configuration

clp can be configured in ~/.config/clp/clprc.lua:

clprc = {}
clprc.theme = "ansi-16"
return clprc

Changing your colorscheme

Instructions available here.

Contributing

Contributions are welcome! Feel free to send a pull request on Github or a patch on Sourcehut.

Contributors

jpe90

65 commits

Nomarian

4 commits

gdubicki

1 commits

jeskin-NIST

1 commits

jpe90/clp

writes input files to stdout with syntax highlighting

97

stars

72

commits

Lua

primary language

Feb 4, 2026

updated

README

clp

clp writes input files to stdout with syntax highlighting. It aims to be relatively fast, provide wide language support, and be easy to extend with new languages. It currently supports 150 languages.

clpm

Language support is implemented with LPEG, a tool developed by PUC which uses parsing expression grammars to improve upon traditional regex parsers (described in depth in this article).

More information is available here, along with a blog post showing how I use it with fzf.

Installation

MacOS

brew tap jpe90/clp
brew install jpe90/clp/clp

Linux

AUR

Building from source

Requirements:

  • a POSIX compliant operating system
  • a C99 Compiler
  • Lua >= 5.1 or LuaJIT (the latter for better performance)
  • LPEG
  • luautf8
$ ./configure
$ make
# make install

Distro Specific Dependencies

Ubuntu
# apt-get install -y build-essential pkg-config libluajit-5.1-dev lua-lpeg
# luarocks --lua-version=5.1 install luautf8
Arch
# pacman -S --needed --noconfirm base-devel pkg-config luajit lua51-lpeg lua51-luautf8

Usage

$ clp [options] filename

Convenience script (example)

An example helper script is included at scripts/sp. It uses rg + fzf and previews with clp. This is only an example, and it opens files with Neovim (nvim) on ctrl-o. Adjust it to your editor and workflow as needed.

-t, --override-filetype {filetype}

Force a language's syntax for highlighting the file. To see available filetypes, run clp --list-overrides

-h, --highlight-line {number}

Highlight a non-blank line

Motivation

Existing syntax highlighting programs are either relatively slow or support a small number of languages. clp aims to be faster without compromising on language support.

Here are some quick benchmarks comparing similar programs running on my machine (clp installed with LuaJIT, highlighting sqlite3.c)

CommandMean [ms]Min [ms]Max [ms]Relative
clp sqlite3.c216.6 ± 2.4212.2220.81.00
bat --color=always sqlite3.c3161.0 ± 12.33149.73182.714.59 ± 0.17
source-highlight sqlite3.c4313.6 ± 25.54277.74355.919.91 ± 0.25

More benchmarks are available here

Parsers are upstreamed from the Scintillua project. It's actively maintained, has great support even for niche languages, and easy to use relative to other syntax definition mechanisms.

Configuration

clp can be configured in ~/.config/clp/clprc.lua:

clprc = {}
clprc.theme = "ansi-16"
return clprc

Changing your colorscheme

Instructions available here.

Contributing

Contributions are welcome! Feel free to send a pull request on Github or a patch on Sourcehut.

Contributors

jpe90

65 commits

Nomarian

4 commits

gdubicki

1 commits

jeskin-NIST

1 commits

Languages

Lua

96.8%

C

2.9%