I was setting up my work mac the other day and finally got round to implementing an alias for syntax highlighting the cat bash command. It’s very quick and simple.
Firstly, install pygments. Brew won’t work so you’ll need to run:
(I was required to use sudo for the above command but you ought not yourself. This was due to using a computer provided by work which had restricted write permissions for non root users.)
<!– Also, as Keir pointed out to me in the comments, "If you’ve installed python with homebrew… you can simply do:
pip install Pygments“. In this instance, I hadn’t –>
After that just throw a convenient alias in your .bashrc and you’re away:
alias c='pygmentize -O style=monokai -f console256 -g'
2 thoughts on “Syntax Highlighted Cat”
Just a quick heads-up: pip is the preferred way to install python packages now, rather than easy_install. Also, both pip and easy_install shouldn’t be ran with sudo for security reasons.
If you’ve installed python with homebrew (it gives you a more up-to-date version than the one bundled with OS X), then python packages will go in a location where root permissions aren’t needed, so you can simply do:
pip install pygment
I take your point regarding the use of sudo and updated the post to reflect why I used it and why most shouldn’t. I couldn’t get pip install to work after installing python with homebrew so have left that out of the body of the article unless you want to add more explicit instructions.