DEV Community

Cover image for Meet the kat command
Marcos Oliveira
Marcos Oliveira

Posted on β€’ Edited on

2

Meet the kat command

A cat with syntax highlight

I created this command: kat based on GNU cat, but with syntax highlighting. It was made with C++.

I classified it as:

"A cat command, but almost with a chocolate flavor" (slogan)

A reference to the KitKat chocolate! And almost because it doesn't have the Kit πŸ˜ƒ

The kat command is still under development, so not all syntaxes are available. At the end of this article there are those that are already and those that are yet to be implemented, in addition to other features that I want to implement.

It's been a while since I created it, but now I've decided to make it available for anyone who wants to use it. It's based on other similar commands that I've seen, but I didn't like them as much and I needed it to be:

  • Simple
  • Fast
  • Beautiful
  • and basic.

The other similar commands were missing something, such as: source-highlight(also made with C++, but not very nice looking), Theldus/kat(made in C, but I didn't like the look either), bat(initially made with Go/Golang, it used to be quite fast, but then it was rewritten in another language and became very slow, besides having too many features for a cat command), highlight(made with Lua and C++, it is also more than a simple cat command, it has many other features).

Theldus/kat has also made a comparison with bat (very slow) and cat. terroo/kat is in the same performance line, that is, since it is an immediate utility, it needs to be fast:

kat performance

Anyway, I was left with creating my own solution!


How to install kat?

kat is currently only available for UNIX-style systems. So, to compile beforehand you need some dependencies, which are:

You can use your system's package manager and install, for example, on Ubuntu:

sudo apt update
sudo apt install build-essential cmake libboost-regex-dev
Enter fullscreen mode Exit fullscreen mode

Then just clone, build and install:

git clone http://github.com/terroo/kat build-kat
cd build-kat
cmake -B build .
cmake --build build
sudo cmake --install build
Enter fullscreen mode Exit fullscreen mode

After installing, you can remove the cloned directory: cd .. && rm -rf build-kat.


How to use kat?

Just like you use cat, the difference is that it already has line numbering, so it doesn't need an additional parameter, examples:

kat main.cpp # C++
kat main.c # C
kat MyClass.java # Java
kat script.py # Python
kat index.js # JavaScript
kat Main.cs # C#
kat.txt # Text
Enter fullscreen mode Exit fullscreen mode

The output will be similar to the image below:

kat C++ example

As I said, there aren't many parameters available, who uses all the cat parameters, for example? I think the most I've ever used in my life was -n to see the line numbers.. πŸ˜ƒ

So, to see the kat help, just run:

kat --help
Enter fullscreen mode Exit fullscreen mode

You'll be amazed at the amount of parameters!!! 🀣


As I said, it's still under development, so the languages and formats that have βœ” are available and those that have βœ– are yet to be implemented.

But, if you want to speed up the implementation of any of them, submit an issue in the kat repository.

  • βœ” C++
  • βœ” C
  • βœ” Java
  • βœ” Python
  • βœ” JavaScript
  • βœ” C#
  • βœ– HTML
  • βœ– Markdown
  • βœ– CSS
  • βœ– JSON
  • βœ– YAML
  • βœ– XML
  • βœ– Go
  • βœ– Swift
  • βœ– Moon
  • βœ– GNU Assembler
  • βœ– Intel Assembly(NASM)
  • βœ– GNU Bash
  • βœ– Power Shell

In addition to implementing in the future: Ruby, PHP, Elixir, Perl, Zig, Rust, Erlang, Haskell and others.

I hope you like kat, ahhh... leave a ✰ in the repository! 😎

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay