iTerm2 offers a way to notify you when a long-running command has finished
- Published at
- Updated at
- Reading time
- 2min
We all know the problem; sometimes, you run a terminal command, and it takes ages. In the meantime, you start browsing YouTube or Twitter and completely forget about the thing you wanted to do. Thirty minutes later, you discover that your command finished 25min ago.
To work around this problem, I usually have snippets for common commands ready that notify me when they are finished. The say
command is a popular choice to let your computer speak to you.
<command> && say "done"
For daily long-running commands, this approach works very well, but some commands take more time unexpectedly.
While reading the excellent labnotes newsletter, I learned that iTerm2 offers telling you when a command has finished. It doesn't require changing or chaining your slow CLI command.
To let iTerm notify you, you must have iTerm's shell integration installed. The shell integration comes with many advanced functionalities to make your CLI life more manageable, and it includes marks. After installing the shell integration, go into program controls, navigate to Edit -> Marks and Annotations -> Alerts
and enable Alert on next mark
.
You might ask, "Okay, cool! But what's a mark, Stefan?". According to the iTerm docs, marks are history entries.
Marks are saved locations in history. They make it easy to navigate to previous shell prompts or other locations of interest.
Whenever a new entry is written to the shell history, iTerm registers a new mark. And for these marks, you can turn on notifications. ๐ After enabling notifications you see an eye displayed in the right corner.
The handy thing about this feature is that you can enable it via a shortcut (cmd + alt + a
), too. Kick off a long-running npm install
, hit the key combination, and start browsing Twitter without wasting too much time, because you'll get notified when your command has finished. Awesome!
If you want to learn more about all the iTerm features I use (the status bar, ZSH theme, etc.), check out my post Settings to emojify and prettify your terminal . ๐
Join 5.5k readers and learn something new every week with Web Weekly.