Powerline for Bash

Earlybyte
Earlybyte
Feb 3 · 5 min read
Use Powerline to make your git repository visible.

TLDR

How to configure Powerline for bash on Ubuntu and macOS to make working with git more convenient and unleash the power of instant git repository status visibility.

Comparison with and without Powerline: How to check git status with branch information.

Git and Bash

When developing on Linux and macOS, git is almost natively integrated into the shell, working seamlessly together with the user’s SSH keys. Additionally, it gives a straightforward usage on one of the most powerful tools in terms of code version control. Even though handling git in the shell is quite convenient for users that are experienced with the commands of git, bash itself does not show git related information by default. Therefore, commands like “git status” are used very often to clarify if one is working in the right branch and whether files have been created, changed or deleted.

Powerline for Bash

In order to make it more convenient when working with git in bash, powerline could be used to display this hidden information. Configured in the right way, Powerline gives a brief overview over the used git repository uncovering the current branch one is working in and showing small but useful details about new, changed or deleted files and whether un-pushed or un-pulled changes exist.

Comparison with and without Powerline: Unveil hidden repository information.

Although, Powerline is written in Python and can be easily installed with pip, many documentations describing the configuration of Powerline aren’t straight forward leaving quite some user with the frustrating reality of having an only partially working solution. Since I was one of those frustrated users, I want to give it a shot trying to explain the process of getting Powerline to work in a more complete way for Ubuntu and macOS.

Installation and configuration

Ubuntu

(Tested on 19.10)

Since Powerline is provided via pip, the first step is to install pip3 if we do not already have it on our system.

Install pip3:

Install Powerline:

Start powerline by adding it to ~/.bashrc file:

Logout and log back in.

With this configuration, when starting a new terminal we will already see Powerline popping up. Unfortunately, this does not yet show any git related information when changing your location into a git repository. To make Powerline working with git as described, there is something more we need to do.

Installing Powerline Gitstatus:

Open the following file and add the lines after the “attached_clients” entry:

~/.local/lib/python3.7/site-packages/powerline/config_files/colorschemes/default.json

Open the following file and change the lines:

~/.local/lib/python3.7/site-packages/powerline/config_files/themes/shell/default.json

Change line from:

To:

Finally, we need to install the Powerline font enabling our shell to show all the special characters and icons correctly.

Go to your Download directory and clone the Powerline font git repository and install the fonts:

To use the newly installed fonts in the terminal open preferences and open the selected profile. Check “custom font” and change the font to “Source Code Pro for Powerline Regular”.

macOS

(Tested on macOS Mojave)

Since Powerline is provided via pip, the first step is to install pip3 if we do not already have it on our system.

Easiest way is to install an up to date pip3 is by using Homebrew (https://brew.sh):

Once pip3 is installed, we can use it to install Powerline:

Start powerline by adding it to ~/.bash_profile file:

Logout and log back in.

With this configuration, when starting a new terminal we will already see Powerline popping up. Unfortunately, this does not yet show any git related information when changing your location into a git repository. To make Powerline working with git as described, there is something more we need to do.

Installing Powerline Gitstatus:

Open the following file and add the lines after the “attached_clients” entry:

/usr/local/lib/python3.7/site-packages/powerline/config_files/colorschemes/default.json

Open the following file and change the lines:

/usr/local/lib/python3.7/site-packages/powerline/config_files/themes/shell/default.json

Change line from:

To:

Finally, we need to install the Powerline font enabling our shell to show all the special characters and icons correctly.

Go to your Download directory and clone the Powerline font git repository and install the fonts:

To use the newly installed fonts in terminal open preferences (click “Terminal” in the top bar, then Preferences) and open the selected profile. Change the font to “Source Code Pro for Powerline Regular”.

Visual Studio Code

Since, I am using Visual Studio Code, I did recognize that Powerline does not out of the box display properly in the integrated terminal. To Improve this behaviour, the settings for the integrated terminal should also be changed:

Terminal Integrated Font Family → Source Code Pro for Powerline

The more detailed way on doing so is described here:

Alternative to Powerline

Recently a friend told me about another very convenient Powerline like solution that is somewhat more modern (includes Emoticons ;-)) and is easier to install. So, for people who are interested in I thought it would be nice sharing it here as well: https://starship.rs/

About the Author

Remo Höppli, is Co-Founder and Software Engineer at Earlybyte.

Earlybyte is an IT consultancy firm specialized in developing new digital solutions for companies around the world from digitalization to IoT solutions, close to the client and its business embracing agility.

Powerline Repositories

Credits

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade