As you might already know, Cat, acronym for concatenate, is an Unix command to view, combine, and copy text files. This command is one of the most frequently used command in GNU/Linux and Unix-like operating systems, everyday. If you use cat command often, you might want to try 'Ccat'. It is very similar to cat command, but displays the contents with syntax highlighting. The currently supported languages are JavaScript, Java, Ruby, Python, Go, C, and JSON.
Installing Ccat
Ccat is available in AUR, so you can install it using any AUR helpers, for example Yay, in Arch Linux and its variants like below.
$ yay -S ccat
On other Linux distributions, you need to compile and install Ccat as shown below.
Download the latest ccat binary from here.
$ wget https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz
Extract the downloaded archive file:
$ tar xfz linux-amd64-1.1.0.tar.gz
Copy the ccat executable file to your system $PATH (for example, /usr/local/bin/):
$ sudo cp linux-amd64-1.1.0/ccat /usr/local/bin/
Finally, make it executable using command:
$ sudo chmod +x /usr/local/bin/ccat
How to colorize Cat command output using Ccat
The usage is very similar to cat command. Let me show you some examples.
To view a text file, for example test.txt, using cat command, we use:
$ cat test.txt
Now, view the text file with "ccat" and see how it displays the output.
$ ccat test.txt
Did you notice the difference? ccat displays the output with syntax highlighting whereas cat command simply displays output in the system's default theme color.
We can also display the output of multiple files (i.e concatenate) at once like below.
$ ccat test.txt example.txt
For some reason, you may want to display the output in HTML format. To do so, just add "--html" option at the end.
$ ccat test.txt --html
Not just local files, we can also directly display the contents of a file in the web like below.
$ curl https://raw.githubusercontent.com/jingweno/ccat/master/main.go | ccat
To view the default applied color codes, run
$ ccat --palette
You can, of course, set your own color codes like below.
$ ccat -G String="_fuchsia_" -G Plaintext="darkteal" test.txt
If you like ccat and wanted to replace the default cat command with ccat, just create an alias.
If you installed it from AUR in Arch Linux, add the following line in your ~/.bashrc file.
alias cat=ccat
If you installed it from the compiled binary file, add the following line in ~/.bashrc file.
alias cat='/usr/local/bin/ccat
Finally, run the following command to take effect the changes.
$ source ~/.bashrc
To add it system wide, add the above entry in /etc/bashrc (On RPM based systems) or /etc/profile (on Debian based systems) file.
Resource:
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Reddit | Facebook | Twitter | LinkedIn | RSS feeds
Have a Good day!!