can iTerm2 colorize on-the-fly using regexps?

978 views
Skip to first unread message

Pete Siemsen

unread,
Oct 5, 2017, 7:03:07 PM10/5/17
to iterm2-discuss
I'm a macOS Terminal user who has been intrigued by iTerm in the past, and even tried it, but never quite made the switch away from Terminal. iTerm2's recently-added features look impressive, so I plan to take another look.

Anyway, today I was working with a power Windows user. There was the usual friendly banter and OS-bashing. He was using a thing called mobaXterm, which has a terrific feature called "syntax coloration". It simply recognizes regular expressions in the stream being displayed, and colorizes them. As a network engineer, it's great to see keywords and IP addresses color highlighted on-the-fly. I had to concede that my Mac had nothing like it. Unless maybe iTerm2 can do it?

There is a demo of the feature in action at https://blog.mobatek.net/post/mobaxterm-new-release-8.6/

Jamie Lawrence

unread,
Oct 5, 2017, 7:06:39 PM10/5/17
to iterm2-...@googlegroups.com

> On Oct 5, 2017, at 4:03 PM, Pete Siemsen <sie...@ucar.edu> wrote:

> Anyway, today I was working with a power Windows user. There was the usual friendly banter and OS-bashing. He was using a thing called mobaXterm, which has a terrific feature called "syntax coloration". It simply recognizes regular expressions in the stream being displayed, and colorizes them. As a network engineer, it's great to see keywords and IP addresses color highlighted on-the-fly. I had to concede that my Mac had nothing like it. Unless maybe iTerm2 can do it?


Yep. Check Profiles -> Advanced -> Triggers. (You can also do other things than coloring.)

-j

Pete Siemsen

unread,
Oct 5, 2017, 7:28:39 PM10/5/17
to iterm2-...@googlegroups.com
Thank you. Since I posted, I downloaded iTerm2 v3.1.2, and tried it.
It looks like triggers does exactly what I want. Cool!

Is there a mechanism to share a set of regular expressions? I'd like
to have a set of regular expressions that make sense when connected to
Cisco routers, and another for Juniper routers, etc. Of course, if
someone has already done the work, in a way that I can load into
iTerm, that would be great.

The regular expression for matching an IPv6 address is not trivial :-)

-- Pete
> --
> You received this message because you are subscribed to a topic in the Google Groups "iterm2-discuss" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/iterm2-discuss/eTA2LLZIyGk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to iterm2-discus...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jamie Lawrence

unread,
Oct 5, 2017, 7:38:36 PM10/5/17
to iterm2-...@googlegroups.com

> On Oct 5, 2017, at 4:28 PM, Pete Siemsen <sie...@ucar.edu> wrote:
>
> Thank you. Since I posted, I downloaded iTerm2 v3.1.2, and tried it.
> It looks like triggers does exactly what I want. Cool!
>
> Is there a mechanism to share a set of regular expressions? I'd like
> to have a set of regular expressions that make sense when connected to
> Cisco routers, and another for Juniper routers, etc. Of course, if
> someone has already done the work, in a way that I can load into
> iTerm, that would be great.

So, someone else will have to answer about sharing settings - I know there are various things people do, but I've paid little attention to that.

As far as sets of regex triggers, notice that you're building these in a profile. So you can set up a profile for Juniper, Cisco, etc. You can also automatically switch profiles based on some combination of host, path and user, but only if you have a shell on the remote machine that can run installable scripts. So that won't work on most network kit. (See Automatic Profile Switching, also on the same tab as Triggers.)

> The regular expression for matching an IPv6 address is not trivial :-)

Heh. Yeah, that gets a little gross at some point.

-j

Aaron Meurer

unread,
Oct 5, 2017, 7:46:38 PM10/5/17
to iterm2-...@googlegroups.com
The gear button on the profile settings lets you export them as JSON,
and also merge profile settings together. I don't see a way to import
them, but I'm assuming that if there's an export option there must be
a way to do an import.

Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "iterm2-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to iterm2-discus...@googlegroups.com.

Richard Mitchell

unread,
Oct 5, 2017, 8:17:49 PM10/5/17
to iterm2-discuss


On Thursday, October 5, 2017 at 7:46:38 PM UTC-4, Aaron Meurer wrote:
The gear button on the profile settings lets you export them as JSON,
and also merge profile settings together. I don't see a way to import
them, but I'm assuming that if there's an export option there must be
a way to do an import.

Aaron Meurer


You can put the text files into: $HOME/Library/Application Support/iTerm2/DynamicProfiles
with the name something like  Dyn-NAME.json
iTerm2 will then automatically make them available.  I use a cmdline script and tcsh completion to show and select from the profiles I've created.
Reply all
Reply to author
Forward
0 new messages