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/

7 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
  3. Thanks for sharing an informative blog keep rocking bring more details
    mobile application development training online
    mobile app development course
    mobile application development training
    mobile app development course online
    mobile application development course
    online mobile application development
    learn mobile application development

    ReplyDelete
  4. Do Yorkie Poos get along with cats?
    yorkies for sale
    While most Yorkies do great with cats, there are always going to be some instances where it just does not work out. Of course, it is best if you go plan for this rare but possible circumstances in which the only answer is, unfortunately, to keep them separate at all times or to find a new home for one of them. yorkie puppy for sale near me

    Do Yorkshire terriers bark a lot?
    Yorkshire Terriers are little dogs with huge personalities. With those huge personalities come a fierce territorial bark. Any time your phone rings, someone speaks or knocks on your door, or your doorbell chimes, your Yorkshire Terrier will likely bark. Outside noises aren't even required for barking for some Yorkies. yorkie for sale near me

    Are Yorkies hard to train?
    Are Yorkies easy to train? Yorkies are not the easiest breed to train. yorkie poo for sale It's not because they aren't smart; they are quite an intelligent breed. But they tend to be confident, curious, and a bit stubborn—all of which can make training more difficult. yorkie for sale





    ReplyDelete