iTerm tip: add custom badges on a per-directory basis

Adrian Cooney
2 min readJan 21, 2017

--

This is a quick tutorial on how I use iTerm’s badges to reduce the impact of context switching when you have multiple windows open in your terminal.

When working with multiple open windows in your terminal, it’s tough to remember which window is doing what when switching back to the terminal from your editor, browser or the various other tools in your development workflow. It’s especially noticeable when you have long running commands spewing text on screen. To make things a little easier, I’ve added visual cues in the form of emojis to the top right hand corner of each window via iTerm’s badge functionality. The emojis are based on the current working directory of the window and automatically update whenever you move around your filesystem.

  1. Create your .badges file in your home directory (~/.badges). This is a simple list of paths and emojis (or any text for that matter) to display as badges with top-down priority (the first matching path is picked). Sub directories are included and the icon will be displayed in them.

2. Install iTerm’s Shell Integration.

3. Add the following code to your .bashrc or .zshrc. It uses iTerm’s shell integration to set the “badge” property on the user var (see the next step).

4. Add the “\(user.badge)” to your Badge in your profile.

5. Appreciate your pretty badges.

Although it might seem superficial and distracting right now, I’ve found the icons essential when working in closely related projects with differing versions. They’ve saved me tons of time avoiding silly mistakes and understand what’s going in each window. iTerm’s badges are a very powerful and underrated feature that needs some lovin’.

--

--