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! 😎

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video πŸ“ΉοΈ

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

πŸ‘‹ Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay