Ccat – Colorize Cat Command Output

In this article, we will learn to use the Ccat tool to make our terminal output look good and vibrant.

Ccat is a command line tool that works like the cat command in linux, where the cat is a standard command in linux used for various operations like printing the file content in standard output and concatenating files. But Ccat does something cooler, Ccat uses syntax highlighting by default for its standard output to the terminal, making it look good to see.

Ccat supports popular languages like Java, Javascript, Ruby, JSON, Go, Python, and C.

Installing Ccat:

To install the the Ccat command in your machine follow the specific instructions according to your machine architecture.

For Linux other than Arch-based distributions,

  • Download the latest Ccat package from the Official GitHub release page or use the below command.
wget https://github.com/owenthereal/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz



downloading ccat from GitHub release page

  • Extract the tar file using the below command.
tar -xvf linux-amd64-1.1.0.tar.gz


extracting tarball of ccat

  • Copy the binary file to the $PATH folder variable such as `/usr/bin` or `/usr/local/bin`.
sudo cp linux-amd64-1.1.0/ccat /usr/bin


copying binary to /usr/bin

For Arch Linux,

  • Ccat package is available in the Arch User Repository (AUR), use any helpers like yay, paru to install the package.
yay -S ccat

For OSX,

  • Use the brew package manager to install the ccat package.
brew install ccat

For Windows,

  • Download the tar package from the release page according to your machine architecture.
  • Extract the tar into a desired folder.
  • Add the folder to the path variable.

How to View Text file Using Ccat?

To view a single text file, pass the file name as argument to the ccat command.

ccat sample.txt

viewing single text file

How to View multiple files using Ccat?

To view multiple files using ccat, pass the file names as argument one by one. Ccat will print contents every file in order which you have provided. For example:

ccat sample.txt sample2.txt sample3.txt

In this command, ccat' will print the contents of each file in the order you have provided. It sequentially displays the content of file1.txt', followed by afile2.txt, and then file3.txt. This allows you to conveniently examine the contents of multiple files in the same terminal window, providing a quick overview of their content without having to open each file individually. Each file’s content is displayed with syntax highlighting, enhancing readability for various programming languages

viewing multiple files

How to view code of any programming language using Ccat?

To view any programming languages code using ccat, pass the file name as argument.

ccat hello.c

  • ccat: This is the command-line tool being used. It is a variant of the traditional cat' command, but with added features such as syntax highlighting.
  • hello.c: This is the argument provided to ccat', specifying the file to be displayed. In this case, it’s assumed that there’s a C programming language source code file named ‘hello.c'.

viewing code files

  • Ccat uses its default pallette color to print the code output in the terminal. Incase you want to use a different highlighting colors, you can feel free to do so by passing the required color code parameters.
  • To view the palette color code parameters, use the below command.
ccat --palette

ccat color palette

Now, choose the preferred color for highlighting from that list of colors and map it to the type of content to be colored with that.

ccat -G String=color_code_name -G Keyword=color_code_name file_name


using custom codes with ccat

How to Display content from the internet using Ccat?

Ccat can also display content from the internet by using pipe with curl command, use the command below.

 curl https://raw.githubusercontent.com/ragul-engg/gfg_potd/main/src/september/FirstSetBit.java | ccat -G String="red" -G Plaintext="brown" -G Keyword="fuchsia"


viewing file from internet with ccat

Viewing output in HTML:

  • Ccat also provides output in the html format. To view the output in html format pass the `–html` flag to the command.

viewing output in html

  • Viewing HTML file in terminal is not useful, but saving the html and viewing it in a browser will help us to see the ccat –html output visually better.
  • Store the Ccat –html output in a file, and go to the html path in a browser.
  • Here > is used to redirect the stdout to index.html.
ccat filename --html > index.html

creating html output file

viewing output file in browser

Using Ccat instead of cat:

  • There are numerous features provided by the Ccat package no wonder if you want to use it instead of cat command.
  • To do this create an alias name `cat` and place the path of the Ccat command.
  • So Ccat command will be triggered whenever you use cat command in your terminal.
  • Open your .bashrc file under your user home directory.
  • Add the below lines in the file to create the alias.
alias cat=/usr/bin/cat

  • Reload the bash with the source command.
source $HOME/.bashrc

  • Now the ccat command will be used, even if you use cat command in the terminal.

a

Getting Help in Cat:

To get help and view the options available in ccat, use the –help flag with cccat.

ccat --help

ccat help command

Conclusion:

In summary, Ccat stands out as a powerful replacement for the conventional cat' command on Linux. Its ability to provide syntax highlighting for various programming languages, customizable color coding, and support for HTML output elevate the command-line experience. The straightforward installation process, compatibility with different operating systems, and the option to create an alias for ‘cat' make Ccat a valuable addition to the Linux toolset. Users can enjoy enhanced readability, comprehension, and visual appeal when viewing files, snippets from the internet, or even creating HTML-formatted content. Embracing Ccat enriches the terminal usage with an aesthetically pleasing and feature-rich alternative to the traditional cat command.



Contact Us