Add Syntax highlighting to the cat command for Rubyists

11 Aug 2013

I use the cat command in the terminal every single day to take a peek at source code. When you look at source code in terminal you probably want it to be syntax highlighted. In this article I’m going to show how you can do it using the excellent coderay gem.

This is how I did on my Mac:

gem install coderay
rbenv rehash

echo 'alias cat="coderay"' >> ~/.bashrc
source ~/.bashrc

cat my_source_file.rb

This is how it will look in the terminal when using coderay:

comments powered by

Contact me