christa
Posted on September 6, 2022
The Issue
Have you ever had the issue of scrolling through long blocks of output in your terminal and miss errors and warnings entirely. This kept happening to me frequently until I finally had enough and took it to Google.
iTerm2 has a text highlighting feature that offers the solution needed to stop missing those errors.
The Solution
Highlight Text offers a wide variety of features and abilities, but today we're going to utilize it to use regular expressions to check for different kind of messaging.
Enable Highlighting
In your iTerm2 Profile settings (iTerm2 Preferences => Profiles) switch to Advanced and look for the Triggers section. Click Edit to add your own triggers. Select the '+' symbol at the bottom left to create a new one.
Add the following regular expression to react on lines containing the text "error":
(?i:.*(error|fatal).*)
Flags are placed at the start of the regex. We use the case insensitive flag i
so the regex starts with ?i:
. After the colon, the regular expression begins.
Select Highlight Text as an action and customize the text color and background as needed. You can either create multiple triggers or define multiple words in your pattern to highlight.
Create a highlight for warnings:
(?i:.*warn|warning.*)
To learn more about the regular expressions, check out regex101 to get more details.
When you are done, your triggers may look something like this:
And the output:
Posted on September 6, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.