Pages

Install Powerline for Mac OS X

Powerline is a shell prompt and statusline plugin for vim, written in Python. It makes working with terminal much more fun and colorful. Here is an example of how the prompt looks like with Powerline.

As you can see from the screenshot, powerline gives you a colorful and visual attractive prompt. If you are in a git repository, it also tells you which branch you are currently working on. It also tells you the exit code of previous process (the number in the last red tab), etc. In this post, I'll show you how to install and setup powerline for Mac OS X bash shell and vim.

Installation

First, make sure you have python version 2.6 or later. Then download and install pip


$ python --version
Python 2.7.5

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py

If you didn't know, pip is a package management system used to install and manage software written in Python. It's equivalent to npm for nodejs or Maven for Java. Now you can use pip to install powerline


$ pip install --user git+git://github.com/Lokaltog/powerline

$ pip show powerline
You are using pip version 6.0.7, however version 6.0.8 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Powerline should be installed at ~/Library/Python//lib/python/site-packages/powerline. In my system, it's at ~/Library/Python/2.7/lib/python/site-packages/powerline

Configuration

You will need to get powerline source code either by cloning it from git repository or download its zip file. Then copy the powerline/ and scripts directories from source code directory to where you had powerline installed.


$ POWERLINE_PATH=~/Library/Python/2.7/lib/python/site-packages/
$ git clone https://github.com/powerline/powerline.git
$ cp -r powerline/powerline/ $POWERLINE_PATH/powerline
$ cp -r powerline/scripts/ $POWERLINE_PATH/scripts

To activate powerline, you need to tell .bash_profile to load powerline.sh file.


$ vi ~/.bash_profile

POWERLINE_PATH=~/Library/Python/2.7/lib/python/site-packages/powerline
source $POWERLINE_PATH/bindings/bash/powerline.sh

Now, create a configuration directory for powerline in your home directory and copy the config_files/ directory from the source code directory there.


$ mkdir ~/.config/powerline 
$ cp -r ./powerline/powerline/config_files/ .config/powerline/

Changing fonts

The source code that you have just cloned earlier comes with 1 font in the font/ directory (PowerlineSymbols.otf). But you can find more fonts for powerline here. Use Font Book to install font you like.

Display git branch

In order to display git branch in powerline prompt, you need to look for settings for shell in config.json and replace default theme with default_leftonly.


$ vi ~/.config/powerline/config.json

"shell" {
  ....
  "theme": "default_leftonly",
  ...
}

Enable powerline for vim

Add the following into .vimrc to enable powerline for vim.


$ vi ~/.vimrc
set rtp+=$HOME/.local/lib/python2.7/site-packages/powerline/bindings/vim/

2 comments:

  1. Hmmm I couldn't get this to work. I'm using ZSH and I changed
    `source $POWERLINE_PATH/bindings/bash/powerline.sh`
    to
    `source $POWERLINE_PATH/bindings/zsh/powerline.zsh`

    but it's still not working for me.

    ReplyDelete
  2. After a lot of digging and this post got me 90% of the way there. The last part was setting the font correctly in the .vimrc file which I found here: http://stackoverflow.com/questions/19105279/how-can-i-setup-my-vim-airline-or-vim-powerline

    ReplyDelete