On June 14, 2017 in Development
Custom iTerm2 Titlebar Background Colors
Make your iTerm2 setup look as beautiful as Hyper. iTerm2 supports proprietary escape codes to achieve just that. Read the story to find out how they work.
- Terminal
- iTerm2
- Themes
- DevTools
- macOS
If you are like me, you get pretty obsessed about the look and feel of your development environment. It’s such a productivity waste, but I am a sucker for nice looking apps. After all, as a dev, you look at this stuff all day.
Over the past years, Electron apps have become all the rage. If you look at a typical JavaScript dev’s development environment these days, you will probably notice them running either Atom or Visual Studio Code (VSCode) for their editor and Hyper for their terminal emulator. In particular VS Code seems to have become the default editor for most. Personally, I do not really like the look of VS Code. Yes, it has made a lot of progress and there are some cool themes, but to me, it still really looks like a Microsoft product. At least as soon as you start digging a level deeper. Atom and Hyper on the other hand, not so much. Look at these two beautiful apps next to each other. They are 🔥🔥🔥🔥.
Sadly, though, I cannot get myself to use these apps for work. I am used to Neovim/Vim and Atom’s model for splits is way too different. It just does not feel right. And while Hyper is beautiful and its plugin system rocks, as soon as I try to run Vim in it, I start noticing all kinds of performance related glitches and lag. On top of all of that, these Electron apps just take too much of my system’s resources. Today, I noticed Atom causing 150% CPU load when I was scrolling its settings screen. Scrolling. Both apps regularly take up gigabytes of memory.
So, I am stuck with my iTerm2, tmux, Neovim combo, which is not easy to get to look really nice. With enough patience and determination, I think I ended up with a nicely looking setup (getting theme colors to work has become a lot easier thanks to True Color support across the stack). You be the judge.
However, one thing that always bothered me was iTerm’s grey titlebar. In the nightly builds, George Nachman has added support for macOS’ dark mode for the titlebar. This is nice, but still does not look as beautiful as Hyper.
Recently, I finally — by accident — found a solution to this problem. 🎉 Turns out, iTerm2 supports some proprietary escape codes for overwriting certain settings. And yes, there are codes to change the titlebar background color!
Here is how to set the titlebar color to the background of the iTerm2 One Dark theme I am using. Type the following into your iTerm2 terminal.
$ echo -e "\033]6;1;bg;red;brightness;40\a"$ echo -e "\033]6;1;bg;green;brightness;44\a"$ echo -e "\033]6;1;bg;blue;brightness;52\a"
This is what it looks like.
Finally. iTerm will not save this to your settings. The solution is to automatically execute the above commands when launching a new session. Just add them to your .bashrc or .zshrc, etc.