Geeking Out

Using Powerline for awesome statuslines

The Powerline project provides a framework and set of configurations for awesome statuslines in Vim, various shells, tmux/screen, and other command line applications. I use Powerline under Mac OS X for my Bash prompt and it looks great. Here’s how I did it.

  1. Be running reasonably current versions of Python (2.7+), Vim, Tmux, Bash, etc. I install these things with Homebrew and highly recommend it — lighter-weight and simpler than other Mac package managers, with a lot of concern for not messing up your existing built-in programs.
  2. Install Powerline using PIP from a custom location: pip install --user git+git://github.com/Lokaltog/powerline
  3. Install a Powerline-compatible font (with various fancy glyphs in unreserved Unicode space). Patched fonts are available here, just download the blob and (on the Mac) double click it to install. I love Menlo, which is not in that repository but is available here.
  4. Setup and customize Powerline, see below.

Powerline is happiest with Zsh because it allows for prompts to be built out from both the left and right. Bash is not so nice, and so the default Powerline Bash display prompt is not great. The standard theme (which only displays the “left” segments in Bash) leaves out important things like Git status/branch info. The “default_leftonly” theme, is better, but it still puts a lot of information, uncondensed, on a single line, so that you end up with 70 characters of stuff in your 80 character window prior to the insertion point. Not great.

The first thing I did was make sure that Powerline is only loaded when I have it installed, so that I can use the same .bashrc for multiple machines. I did this like so:

[code lang=”bash”]
powerline_path=$(python -c ‘import pkgutil; print pkgutil.get_loader("powerline").filename’ 2>/dev/null)
if [[ "$powerline_path" != "" ]]; then
source ${powerline_path}/bindings/bash/powerline.sh
else
# Setup your normal PS1 here.
fi
[/code]

Then I customized the Powerline display to look better on Bash.

  1. Copy the set of default configuration into a local config dir:
    [code lang=”bash”]
    mkdir ~/.config/powerline
    powerline_path=$(python -c ‘import pkgutil; print pkgutil.get_loader("powerline").filename’
    cp -R ${powerline_path}/config_files/* ~/.config/powerline
    [/code]
  2. In config.json I modified the “theme” for the shell version of Powerline, which was about line 28. I changed it to a new theme name, mine is called “zeno” but name yours whatever you’d like.
  3. Then under themes/shell, I copied default.json to zeno.json.
  4. Edit your new file (zeno.json or equivalent) and look especially at the “segments” section. You want segments only on the “left” side, so move things you want from “right” to “left” and get rid of right. This is all yucky JSON, so be careful of brackets and commas. There is also “segment_data” that customizes how each segment behaves.

I made some changes that work well for me, like removing the domain portion of the hostname and reducing the directory tree display to two directories deep. On errors the error code is displayed in red. All that displays on one line, and on a second line is just my current username and a $ (or # when root). I have found that once I got used to it I quite like the two-line prompt setup.

For simplicity, here is my final file, which comes out looking like this:

My Powerline Prompt

More information about customizing Powerline is available in the docs.

If you run into any weird problems, here are a bunch of troubleshooting tips from the Powerline developers.