SSH Syntax Highlighting

Highlighting your Session to Make Configs & Debugs Easier to Read

Posted on:

I was having a conversation in a group chat with some of my old colleagues turned friends the other day when the conversation turned to Linux vs. Windows. One of my friends, who is a network engineer and spends a good portion of his day SSH'd into equipment, said something along the lines of "Most of the time I'm fighting my workflow, working in Linux. Like, this is a big one for me. Fucking keyword highlight in SSH sessions dude." I figured this had to be something easy to accomplish, but I've never actually tried. So, I did some searching and before long, I had a very promising solution.



As the GitHub page describes it: "ChromaTerm (ct) is a Python script that colors your terminal's output using regular expressions. It even works with interactive programs, like SSH."

Cool, so with this script, we can create a YAML file with regex rules to highlight as we see fit. Now all I need to do is create a configuration to make it useful for network devices. Unless... someone's already done that for me. Using the .chromaterm.yml in this repo as a jumping off point, I've now added a few highlights of my own and customized some of the colors to make it fit what I'm looking for. This really does make a big difference when looking at configs via SSH. My next down time task is going to be adding highlighting for some of the most common (and usually very chatty) debugs I use when troubleshooting SIP and PRI connections for my own job. Once I have some highlights for Cisco CUBEs, I may will post the file.

SSH with CT

The Drawback

I have one small issue with ct. I added ssh() { /usr/bin/ssh "$@" | ct; } to my .zshrc as noted in the readme of the repository and it does work. But, when I SSH to any of my devices that displays its own colors, ct displays them incorrectly. I may see if I can come up with a better way to bypass ct, but for now, I'll be removing the command from my .zshrc and creating an alias like sshc or something so that I can choose to only use ct when I connect to specific devices.

Tagged with:

More posts: