Powerline for Bash

Earlybyte
Earlybyte
Published in
6 min readFeb 3, 2020
Use Powerline to make your git repository visible.

TL;DR

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 users with the frustrating reality of having an only partially working solution. Since I was one of those frustrated users, I want to try explaining 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.8/site-packages/powerline/config_files/colorschemes/default.json

Open the following file and change the lines:

~/.local/lib/python3.8/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”.

Since we have updated the files in the main directory, we can copy the configurations to the user’s home to ensure that the configuration persists even when update change things in the background.

To do so, generate the directory structure in the user’s home:

And copy the configuration files:

macOS

(Tested on macOS Mojave/ macOS Catalina)

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

The easiest way 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 work 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.8/site-packages/powerline/config_files/colorschemes/default.json

Open the following file and change the lines:

/usr/local/lib/python3.8/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”.

Since we have updated the files in the main directory, we can copy the configurations to the user’s home to ensure that the configuration persists even when update change things in the background.

To do so generate the directory structure in the user’s home:

And copy the configuration files:

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 of 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, I thought it would be nice to share 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

--

--