Customize your Terminal prompt with Powerline

Kenta Kodashima
4 min readNov 6, 2018

--

This article is inspired by the medium article titled “How to Jazz Up Your Bash Terminal — A Step By Step Guide With Pictures”. In my article, however, I will do the same thing with Python 3.

Step 1: Install Powerline

1.1: Install Python 3 via Homebrew

Run the command below to install the latest version of Python3.

brew install python3

1.2: Install pip

pip is a package manager for Python which is similar to “npm” for Node.js.

sudo easy_install pip

1.3: Install Xcode Developer CLI tools

Powerline uses XCode Developer CLI tools to manipulate OSX systems. Install Xcode with the code below.
Note: If you already have Xcode installed, you can skip this.

xcode-select —-install

1.4: Install Powerline

Finally, install Powerline.

pip install --user powerline-status

Step 2: Configure Powerline

2.1 Add the Powerline daemon to bash

Open your terminal with the following line. Make sure that you have .bash_profile in your root directory. If you don’t have it, just create one using cd ~ && touch ~/.bash_profile .

vim ~/.bash_profile

Then, add the configuration as below.
Note: You can find the location of your powerline-status with the pip3 show powerline-status command.

# Powerline
export PATH=$PATH:$HOME/Library/Python/3.6/bin
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /Users/yourUserName/Library/Python/3.6/lib/python/site-packages/powerline/bindings/bash/powerline.sh

Step 3: Install Powerline fonts

In order to install Powerline fonts, go to https://github.com/powerline/fonts and follow the instruction. For me, the code below worked.

# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

Step 4: Install Customized Theme for Terminal

Just to make your Terminal look better, let’s install the cool theme called “Iceberg”.

4.1 Download the theme

Go to https://cocopon.github.io/iceberg.vim/ to download the zip file. When you open the zip file, you should see Iceberg.terminal file.

4.2 Import Iceberg in your Terminal

Open up your terminal and go to Terminal > Preferences > Profiles. At the bottom of the left sidebar, there is a gear icon. Click the icon and go to Import, then select the theme you just downloaded(Iceberg.terminal).

Terminal Preference

This will create the new profile. Since you just imported the theme, colors are already set. Just change the font from the default font to Powerline font downloaded in the previous step. You can use any fonts that say “for Powerline”. (I’m personally using “Source Pro for Powerline”.)

Terminal Preferences

Step 6: Add Git Information to Your Prompt

At this point, your Terminal should have working Powerline (restart your Terminal if you want to check). However, it’s more convenient if you can see Git information on your prompt. You can achieve this functionality using “Powerline Gitstatus”.

Go to https://github.com/jaspernbrouwer/powerline-gitstatus and follow the instruction. You just need a few steps.

6.1 Install powerline-gitstatus

pip install powerline-gitstatus

6.2 Configuration

Add the configuration for color schemes in your default.json. The location of your default.json depends on your machine. Try:

vim ${replace-with-your-powerline-installation-derectory}/powerline/config_files/colorschemes/default.json

or

vim .config/powerline/colorschemes/default.json

Opening up you default.json, add the code below.

{
"groups": {
"gitstatus": { "fg": "gray8", "bg": "gray2", "attrs": [] },
"gitstatus_branch": { "fg": "gray8", "bg": "gray2", "attrs": [] },
"gitstatus_branch_clean": { "fg": "green", "bg": "gray2", "attrs": [] },
"gitstatus_branch_dirty": { "fg": "gray8", "bg": "gray2", "attrs": [] },
"gitstatus_branch_detached": { "fg": "mediumpurple", "bg": "gray2", "attrs": [] },
"gitstatus_tag": { "fg": "darkcyan", "bg": "gray2", "attrs": [] },
"gitstatus_behind": { "fg": "gray10", "bg": "gray2", "attrs": [] },
"gitstatus_ahead": { "fg": "gray10", "bg": "gray2", "attrs": [] },
"gitstatus_staged": { "fg": "green", "bg": "gray2", "attrs": [] },
"gitstatus_unmerged": { "fg": "brightred", "bg": "gray2", "attrs": [] },
"gitstatus_changed": { "fg": "mediumorange", "bg": "gray2", "attrs": [] },
"gitstatus_untracked": { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
"gitstatus_stashed": { "fg": "darkblue", "bg": "gray2", "attrs": [] },
"gitstatus:divider": { "fg": "gray8", "bg": "gray2", "attrs": [] }
}
}

Then, add the configuration in your default.json to activate Gitstatus segment. Same as the location of the default.json to configure color schemes, the location of your default.json depends on your machine.

Try:

vim ${replace-with-your-powerline-installation-derectory}/powerline/config_files/themes/shell/default.json

or

vim .config/powerline/themes/shell/default.json

Then, add the following code.
Note: This code should be added to the left block.

{
"function": "powerline_gitstatus.gitstatus",
"priority": 40
}

That’s everything! Enjoy coding with your new Terminal!

References:

How to Jazz Up Your Bash Terminal — A Step By Step Guide With Pictures:
https://medium.freecodecamp.org/jazz-up-your-bash-terminal-a-step-by-step-guide-with-pictures-80267554cb22

How to install Powerline to pimp your BASH prompt (For Mac):
https://medium.com/@ITZDERR/how-to-install-powerline-to-pimp-your-bash-prompt-for-mac-9b82b03b1c02

Powerline:
https://github.com/powerline/powerline

Powerline Gitstatus:
https://github.com/jaspernbrouwer/powerline-gitstatus

Iceberg:
https://cocopon.github.io/iceberg.vim/

--

--

Kenta Kodashima
Kenta Kodashima

Written by Kenta Kodashima

I'm a Software Engineer based in Vancouver. Personal Interests: Books, Philosophy, Piano, Movies, Music, Studio Ghibli.

Responses (1)