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/

6 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
    Replies
    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from Node JS Online Training from India . or learn thru Javascript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Online Training

      Delete
  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. There is a reason why I bought a Mac, it was not to be one of the cool kids that wanted the best of the best. No it was because of the music production I do on it. Hours and hours sitting in front of my Mac copying, pasting, moving, deleting, hour after hour just beating on my Mac in a endless assault to get my work done. That is the key part, my work. I work from home, it is great, but even if it is from home it is still work and it still needs to get done. So my Mac, I have it because it is fast, gets the job done and comes back for more.

    But what happens when it doesn't want to do those things anymore?

    I move around massive amounts of information and yes even on the almighty Mac this can cause a problem after a while. Things fragment, programs get corrupted issues come up. My light speed Mac slows down to a crawl and all of the sudden I simply can not get any work done. Because I work from home there is no IT guy to call and ask to come fix it. No instead I have to figure out what is wrong. I am lucky, I did, but not after trying everything under the sun first and wasting countless hours looking for one program that can do what I needed instead of ten programs. One program to lead them all….okay that was a lame Lord of the rings reference, but that program was/is Detox My Mac. A simple to use program that did not just fix my issues, it put my Mac on overdrive again. A few clicks and my Mac was clean and ready to rock and roll again.

    Read more here:- http://detox-my-mac.com?98274rwehf78t34

    ReplyDelete
  4. There is a reason why I bought a Mac, it was not to be one of the cool kids that wanted the best of the best. No it was because of the music production I do on it. Hours and hours sitting in front of my Mac copying, pasting, moving, deleting, hour after hour just beating on my Mac in a endless assault to get my work done. That is the key part, my work. I work from home, it is great, but even if it is from home it is still work and it still needs to get done. So my Mac, I have it because it is fast, gets the job done and comes back for more.

    But what happens when it doesn't want to do those things anymore?

    I move around massive amounts of information and yes even on the almighty Mac this can cause a problem after a while. Things fragment, programs get corrupted issues come up. My light speed Mac slows down to a crawl and all of the sudden I simply can not get any work done. Because I work from home there is no IT guy to call and ask to come fix it. No instead I have to figure out what is wrong. I am lucky, I did, but not after trying everything under the sun first and wasting countless hours looking for one program that can do what I needed instead of ten programs. One program to lead them all….okay that was a lame Lord of the rings reference, but that program was/is Detox My Mac. A simple to use program that did not just fix my issues, it put my Mac on overdrive again. A few clicks and my Mac was clean and ready to rock and roll again.

    Read more here:- http://detox-my-mac.com?duhhf9265hskfhf98346

    ReplyDelete
  5. There is a reason why I bought a Mac, it was not to be one of the cool kids that wanted the best of the best. No it was because of the music production I do on it. Hours and hours sitting in front of my Mac copying, pasting, moving, deleting, hour after hour just beating on my Mac in a endless assault to get my work done. That is the key part, my work. I work from home, it is great, but even if it is from home it is still work and it still needs to get done. So my Mac, I have it because it is fast, gets the job done and comes back for more.

    But what happens when it doesn't want to do those things anymore?

    I move around massive amounts of information and yes even on the almighty Mac this can cause a problem after a while. Things fragment, programs get corrupted issues come up. My light speed Mac slows down to a crawl and all of the sudden I simply can not get any work done. Because I work from home there is no IT guy to call and ask to come fix it. No instead I have to figure out what is wrong. I am lucky, I did, but not after trying everything under the sun first and wasting countless hours looking for one program that can do what I needed instead of ten programs. One program to lead them all….okay that was a lame Lord of the rings reference, but that program was/is Detox My Mac. A simple to use program that did not just fix my issues, it put my Mac on overdrive again. A few clicks and my Mac was clean and ready to rock and roll again.

    Read more here:- http://detox-my-mac.com?duhhf9265hskfhf98346

    ReplyDelete