Add power to your terminal with powerline

A while ago, Fedora Magazine posted this interview with Rackspace architect Major Hayden where he mentioned the powerline utility. If you often use a terminal, you too might find powerline useful. It gives you helpful status information, and helps you stay organized.

For the shell

By default, the shell plugin gives you plenty of helpful data:

  • Login name
  • Local time
  • Current working directory or path. The path is condensed automatically when it grows longer than the terminal width.
  • The number of active background jobs
  • The hostname, when you connect via SSH to a remote system where powerline is installed

This saves you a lot of twiddling with your shell environment and complex scripting! To install the utility, open a terminal and run this command:

sudo dnf install powerline powerline-fonts

The rest of these instructions assume you’re using Fedora’s standard bash shell. If you’re using a different shell, check out the documentation for tips.

Next, configure your bash shell to use powerline by default. Add the following snippet to your ~/.bashrc file:

if [ -f `which powerline-daemon` ]; then
  powerline-daemon -q
  POWERLINE_BASH_CONTINUATION=1
  POWERLINE_BASH_SELECT=1
  . /usr/share/powerline/bash/powerline.sh
fi

To activate the changes, open a new shell or terminal. You should have a terminal that looks like this:

Terminal with powerline running in the bash shell

Try changing directories. Watch how the “breadcrumb” prompt changes to show your current location. Very handy! You’ll also be able to see number of pending background jobs. And if powerline is installed on a remote system, the prompt includes the hostname when you connect via SSH.

For tmux

If you’re a command line junkie, you probably also know tmux. It allows you to split your terminal into many windows and panes, each containing its own session. But the tmux standard status line is not quite as interesting as what powerline provides by default:

  • Window information
  • System load
  • Time and date
  • Hostname, if you’re connected to a remote system via SSH

Therefore, let’s install the plugin:

sudo dnf install tmux-powerline

Now add this line to your ~/.tmux.conf file:

source "/usr/share/tmux/powerline.conf"

Next, remove or comment out any lines in your tmux configuration for status bar length or content. Examples of these settings are status-left, status-right, status-left-length, and status-right-length.

Your user configuration is stored in ~/.tmux.conf. If you don’t have one, copy an example from the web or /usr/share/tmux to ~/.tmux.conf, and then edit.

When you next start tmux, you should see the powerline status bar:

A tmux session with powerline running the status bar

For vim

If you use the vim editor, you’re also in luck. There’s a powerful plugin for vim, too. By default, it shows:

  • Operating mode (normal, insert, replace)
  • Current path and file name
  • Text encodings
  • Document and line positions

To install it, use this command:

sudo dnf install vim-powerline

Now add the following lines to your ~/.vimrc file:

python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup
set laststatus=2 " Always display the statusline in all windows
set showtabline=2 " Always display the tabline, even if there is only one tab
set noshowmode " Hide the default mode text (e.g. -- INSERT -- below the statusline)
set t_Co=256

Now you can start vim and see a spiffy new status line:

Vim running with powerline status

Configuring powerline

No command line utility is complete without configuration options. The configuration in this case isn’t exactly simple, though; it requires you to edit JSON formatted files. But there’s a complete configuration guide available in the official documentation. And since the utility is written in Python, it’s eminently hackable.

When you hack the configuration, it’s usually to add, change, or remove segments. There are plenty of segments available, such as:

  • Content of environment variables
  • Version control system data (such as git branch and status!)
  • Weather
  • …and many more.

To change the status layout in an environment, you create or edit configuration files in your ~/.config/powerline/ folder. These configurations are stored as themes for each plugin. You can use the powerline-lint utility to check your configuration for parsing errors after making changes.

Some changes may require you to reload your session or possibly restart the daemon:

powerline-daemon --replace

Now you can enjoy more sophisticated status data in your favorite tools!

Using Software

66 Comments

    • qutek

      What is the difference to the normal powerline utility presented in this article

  1. Rizqi N Assyaufi

    dont forget to patched font with powerline-fonts
    https://github.com/Lokaltog/powerline-fonts

  2. JIm

    Powerline looks great! The only issue I have is trying to get tmux to display the status bar below. I created a .tmux.conf file and added source “/usr/share/tmux/powerline.conf” to it, but after exiting the terminal and restarting it, it doesn’t work.

    • JIm

      Never mind, I see you have to start it up. Slaps forehead Coffee kicked in just now. Ha ha!

  3. arielnmz

    I’ll give it a try, looks great!

  4. voyo

    Seems like first important improvement since f18. I was afraid that fedora will be more and more useless. Now let’s also remove gnome control center and use something that will actually work like alsamixer or pavucontrol for music… Just a hint.

  5. Sourav Moitra

    Awesome

  6. edgeman

    I have weird characters instead of nice ones (on F22):
    (snipped to hide username) http://i.imgur.com/1M83Aen.png

  7. Zoltan

    Let’s hope that small utility is gonna be default in every fedora terminal…

  8. cjmannino

    Simply Nice.

  9. Link

    I must be missing something, but I can’t seem to get the right segments in the bash shell to show up (vcs). If I switch to the default_leftonly theme, it works. Is there some width value I’m not setting? Using gnome-terminal.

    • Elliott

      Bash doesn’t allow building the prompt from the right side, so you’d need to use zsh or configure what you want on the left side.

  10. Huskell

    For some reason the tmux powerline doesn’t work here. I start it with the “tmux” command, but only the default appearance shows.

    • Erik

      Have you tried Byobu? It worked for me in tmux via Byobu on the first go.

  11. Lord Drachenblut

    Thanks for pointing out this great tool

  12. Katharina

    Looks good, though I am getting weird characters instead of those pointy arrow segments.
    I’m using the fish shell and several terminal emulators. All of them having this issue:

    http://postimg.org/image/3tpckwo1f/

    Any idea how to fix this? The pointy bits are the cool thing 😛

  13. Joe T.

    Is it possible to run powerline-daemon usefully as a systemwide daemon, or is it intended to be run only per-user?Is it possible to run powerline-daemon usefully as a systemwide daemon, or is it intended to be run only per-user?

    • Martin Vala

      +1

    • Rich

      Instead of appending those lines to .bashrc, create a new file called /etc/profile.d/powerline.sh

      Make permissions and ownership same as its neighbours.

      I’m surprised this isn’t covered in the article; but then all these comments seem to be from 2015-09, and the article was published 2017-07. Maybe in another couple of years’ time, powerline will yet to have been written…

  14. Arun

    How do i setup VCS ? The documentation is poor!

  15. Unfortunately your .bashrc if statement doesn’t work when you remove powerline (so you’re stuck to reinstall it to get access to .bashrc).

    This is one that works for me however more cleanly:

    if powerline is installed, then use it

    command -v powerline-daemon &>/dev/null
    if [ $? -eq 0 ]; then
        powerline-daemon -q
        POWERLINE_BASH_CONTINUATION=1
        POWERLINE_BASH_SELECT=1
        . /usr/share/powerline/bash/powerline.sh
    fi
  16. Tomas Tomecek

    I used powerline for a couple of weeks. It looks really nice, but since it’s written in python, it’s ridiculously slow and tends to traceback. I instead switched to:

    vim-airline in vim
    wrote my own tool for tmux status bar
    created custom prompt for zsh

  17. Roman

    Looks awesome with a fresh and clear look! Currently I am using screen on all machines, especially for remote configuration and shell persistence when disconnected. Will give it a try soon.

  18. Oliverathon

    Hi, I try to powerline with vim but don’t work. please I need to help. I can’t see the file vimrc. it necessary create this file manual?

    • Erik

      You may create the file ‘.vimrc’ in your home directory manually, or you may create a new file in ViM, which should also create a .vimrc. if you’ve never used ViM as that user before, you won’t have a .vimrc file in your homedir.

  19. Sylvain

    (EDIT: check for powerline-daemon instead of powerline)

    The if condition with “which” doesn’t work as expected when you don’t have powerline installed. It shows an error message and without quotes, the condition is always true.

    To fix it, I would suggest to use command instead:

    if command -v powerline-daemon > /dev/null; then
      powerline-daemon -q
      POWERLINE_BASH_CONTINUATION=1
      POWERLINE_BASH_SELECT=1
      . /usr/share/powerline/bash/powerline.sh
    fi
  20. DChrome

    Looks nice.
    However, I am still struggling with the font issue.
    VIM in a terminal window is fine, but in GVIM some characters look weird:

  21. Suvayu

    Is it possible to get it to work with GNU Screen? There is no mention of it other than in the reference for the config option

    common.additional_escapes

    .

  22. Looks nice so far, but I want to have git branch info shown on the powerline. I tried to install powerline-gitstatus (https://github.com/jaspernbrouwer/powerline-gitstatus/issues/new), but get the error “python setup.py egg_info” failed… and I had to quit yak-shaving and get some work done.

    Anyone know what I have to do to get git status info in my powerline prompt in Fedora?

    • Powerline itself actually supports showing the git branch in the bash powerline without installing the powerline-gitstatus plugin. The support in powerline is a lot simpler (it just shows the current branch) than what the powerline-gitstatus plugin gives you.

      There is a little bit of configuration needed to get the powerline –just show the branch — working. You need to enable a different theme that is shipped in powerline on Fedora. To do this:

      1. Make a new directory for your powerline configuration (if you haven’t done so already) in the ~/.config/ directory:
        mkdir ~/.config/powerline
        
      2. Now copy the configuration file that was shipped for powerline on Fedora into this directory:
        cp /etc/xdg/powerline/config.json ~/.config/powerline/
        

        This file is what powerline was using for config, but here we move it to your home directory so we can make changes to it without the risk of that file being changed when powerline is updated. Powerline also looks for config files in ~/.config/powerline/ so this file will take precendence over the one in /etc/xdg/powerline.

      3. Edit ~/.config/config.json changing the “theme” variable in the “shell” section to read “default_leftonly”. That section of the file should look like:
                        "shell": {
                                "colorscheme": "default",
                                "theme": "default_leftonly",
                                "local_themes": {
                                        "continuation": "continuation",
                                        "select": "select"
                                }
                        },
        
        

      Now when you navigate to a directory with a git repo, the branch should show up on the left in the powerline.

  23. What I can’t get to work is to make it also update the terminal window title with current username, host and path.

  24. Fuji

    Paul,
    don’t you have strange characters in the status bar of gvim?
    It is working with vim but not with gvim.
    http://imgur.com/a/FGrBm

    • @Fuji: Hi, I’m sorry but I don’t use gvim, so I don’t know the solution to this issue. Maybe another reader knows and can help you figure it out?

      • Fuji

        It appears that the spaces are not correctly rendered in gvim.
        Take a look at the file /etc/xdg/powerline/themes/powerline.json with gvim, at line numbers 4, 5, 15 or 24 for example, the space after the symbol contains something and is not empty.
        Is this a bug of gvim? Is there a workaround?

  25. Fuji

    Ok I fixed the problem of these strange characters.

    You have to install the fonts from https://github.com/powerline/fonts and then add the following in your .vimrc :
    set guifont=Droid\ Sans\ Mono\ for\ Powerline\ 10

    You can test different fonts for PowerLine in gvim. Just go to “Edit/Select Font …” and choose a font “for Powerline” and then type
    :set
    to get the guifont line to add in your .vimrc.

  26. Schwella

    I successfully installed it and it looks the same as on the screenshots here. So, I think there is a general issue in this configuration, because the section dividers (the triangles) are a little offset. They should be pushed a little bit right. This can be best seen on the gaps of the dividers from the right side. Does anyone know how to fix this ?

  27. S Nambiar

    Looks great. thank you.

  28. Hans Anderson

    In F24, powelines config examples are not stored in

    /usr/share/doc/tmux/examples

    but in

    /usr/share/tmux/

    Unfortunately, powerline doesn’t seem to be compatible with Guake Terminal. First lines of the guake terminal disappear when powerline is up.

  29. Aki

    I am facing the below issues. Could any one help me to solve this issue?

    [aki@localhost /]$ sudo vim /etc/vimrc
    Error detected while processing /etc/vimrc:
    line 66:
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: No module named powerline.vim
    line 67:
    Traceback (most recent call last):
    File “”, line 1, in
    NameError: name ‘powerline_setup’ is not defined
    line 68:
    Traceback (most recent call last):
    File “”, line 1, in
    NameError: name ‘powerline_setup’ is not defined
    Traceback (most recent call last):
    File “”, line 9, in
    ImportError: No module named powerline.vim
    An error occurred while importing powerline module.
    This could be caused by invalid sys.path setting,
    or by an incompatible Python version (powerline requires
    Python 2.6, 2.7 or 3.2 and later to work). Please consult
    the troubleshooting section in the documentation for
    possible solutions.
    Unable to import powerline, is it installed?
    Press ENTER or type command to continue

  30. Terry Glass

    Using powerline with vim-enhanced under Fedora 25 requires changing the lines starting with “python” to “python3” in the example .vimrc.

    • psg_nm

      Using “python3” in the “.vimrc” was also necessary for me under Fedora 24.

      An alternate approach that solved it was to add the following as the first line of the “.vimrc”:

      let $PYTHONPATH=’/usr/lib/python3.5/site-packages’

      But, now that I understand the problem better (needing python3 vs. python), this was just exposing the Python 3 packages to Python 2, which is a bad solution in the long run. Changing “python” to “python3” in the “.vimrc” is a better solution.

  31. Keti Zilgish

    As recommended by Paul W. Frields, I tried to add to the ~/.bashrc file and went and made some mistake due to which I cannot use su anymore to update. The error I get is:
    [keti@localhost ~]$ su
    Password:
    bash: /root/.bashrc: line 10: syntax error near unexpected token

    fi'
    bash: /root/.bashrc: line 10:

    fi’
    bash-4.3#
    It would help a lot if Paul W. Frields could kindly help me salvage the OS.

  32. M Edward/Ed Borasky (@znmeb)

    On Fedora 25 I had trouble with the vim plugin. I got it to work by changing “python” to “python3” in the .vimrc commands.

  33. Chris Townsend

    I too had trouble getting the vim plugin to work until I installed the package via pip:

    pip install powerline-status

    Everything else worked fine as expected.

  34. Is it possible to automate my Terminal for, every time that I start it, it comes with powerline on? I had powerline already running on my Terminal and not just look greats but make me understand more processes and commands. But I could not figure it out how to make it standard on the Terminal.
    Thanks for any advice.

    • @Andre: I have these lines in my ~/.bashrc file:

      if [ -f which powerline-daemon ]; then
        powerline-daemon -q
        POWERLINE_BASH_CONTINUATION=1
        POWERLINE_BASH_SELECT=1
        . /usr/share/powerline/bash/powerline.sh
      fi
      • Thanks Paul! As a musician who loves Fedora, I sometimes make some mistakes (I don’t know a lot a coding, but I am improving it 😉
        Tks a lot!

  35. Gorille

    Powerline works fine in gnome terminal emulator but appears broken in ttys… Does anybody else have this rendering issue? I guess it’s not the fonts since they are included

  36. Christian von Behren

    Can anyone help me to exclude tty sessions to use powerline in bash as they seem buggy (no daemon/wrong font)?

    if [ -f

    which powerline-daemon

    ]; then
    if [ [$(tty)!=/dev/tty*] ]; then
    powerline-daemon -q
    POWERLINE_BASH_CONTINUATION=1
    POWERLINE_BASH_SELECT=1
    . /usr/share/powerline/bash/powerline.sh
    fi
    fi

  37. Peter Parker

    thanks, greetings from Ecuador

  38. kelevra90

    I needed to install glib to make powerline work with tmux. Maybe glib should be added to tmux-powerline’s dependencies.

    • @kelevra90: There shouldn’t be any need to install glib2, nor include it in the dependencies. Without glib2 you can’t have dnf itself installed.

      • kelevra90

        I was speaking of glib not glib2.

        • kelevra90

          I just found out what is causing the problem:

          “This particularly happens on Linux when the distribution provides a version of glib that received Unicode 9.0 upgrades (glib >= 2.50.1) while providing a version of glibc that didn’t (glibc < 2.26).”
          (source: https://github.com/gpakosz/.tmux#troubleshooting)

          I have glibc 2.25 and glib 2.52.3 (glib2 package in f26). Additionally installing glib 1.2.10 (glib package in f26) fixed it.

          So it seems that this isn’t really a problem, because it will get fixed automatically with the next update of the glibc package to a higher version.

  39. Hi there!
    I’m using Fedora 26. I just installed the powerline utility and configured my “bashrc” file just as you’ve advised to do so. However, I’m unable to achieve the fancy bash prompt as you’ve shown in the screenshot above.

    For reference, here’s how my “bashrc” file looks like:
    https://gist.github.com/anonymous/7dee037102399551777ba41c946dec8c

    I’d be glad if anyone could help me.

    Thanks,
    Abdullah

    • @Abdullah: Have you tried moving the powerline stanza to the end of your .bashrc?

      • Just did what you advised and it did the trick. However, could you please explain Why moving the powerline stanza to the end of “bashrc” did the trick?

        Thanks,
        Abdullah

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions

%d bloggers like this: