🤔 Are you backing up your git repositories?

Nick Jones

Product-Focused CTO, Founder,
Software Engineer, Indie Hacker

iTerm2: Showing the PHP, Ruby or Node version in your status bar

Version 3.3.0 of iTerm2 introduces a cool new feature that allows you to customise the status bar. The status bar allows you to modify the top of your prompt to show information about your terminal session, information that’s always present as you’re working.

There are some frequently useful pieces of information that us developers like to know as we’re navigating inside a project, such as what branch we’re on or our present working directory. Typically this is done by modifying the bash prompt to show this information before the caret. This method is challenging to manage and substantially slows down the instantiation of the prompt, sometimes adding seconds on to the start time of a new shell.

I’ve started using this to show me the following useful information:

Getting this configured wasn’t as straight forward as I imagined to get working, so please find instructions on getting this working below.

Screenshot of iTerm with status bar, oh and a cow saying hello


To use this feature, you’ll need:

Configuration File

For this to work, you need to define a shell function for iTerm2 to call. The example below is for bash, but there are instructions for your shell.

# See https://www.iterm2.com/3.3/documentation-scripting-fundamentals.html

function iterm2_print_user_vars() {
    iterm2_set_user_var phpVersion $(php -v | awk '/^PHP/ { print $2 }')
    iterm2_set_user_var rubyVersion $(ruby -v | awk '{ print $2 }')
    iterm2_set_user_var nodeVersion $(node -v)

This creates three new variables: user.phpVersion, user.rubyVersion and user.nodeVersion.

Configuring the Status Bar

You can now use these variables with the “string interpolation” component for the status bar.

You can edit the status components by:

You can use the inbuilt components for the branch and directory display. To use your variables, create three “Interpolated String” components and drag them where you want them.

Click “Configure Component” and use the variables in your output, e.g. PHP: \(user.phpVersion)

Screenshot of status bar component configuration screen