Powerline is a text-based tool that provides useful information in a variety of contexts. The following demo shows Powerline displaying information about a Git repository:
Install Powerline
You can install Powerline from the Universe repository of Ubuntu:
- Add the Universe repository:
sudo add-apt-repository universe
- Install Powerline
sudo apt install --yes powerline
Configure Bash
To configure Powerline for bash, add the following lines to your $HOME/.bashrc
file:
# Powerline configuration
if [ -f /usr/share/powerline/bindings/bash/powerline.sh ]; then
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source /usr/share/powerline/bindings/bash/powerline.sh
fi
To apply the changes to your current terminal:
source ~/.bashrc
After running the previous command or restarting your terminal, the Powerline segments appear in your prompt.
Configure Vim
To use Powerline, Vim requires support for Python 3. You can check the features included in your installation with the following command:
vim --version
Look for the python3 entry, which must have a plus sign (+
) next to it to indicate that the feature is available. If your version of vim doesn’t include support for Python 3, you can install the latest vim package, which at the time of this writing includes support for Python 3:
sudo apt update
sudo apt install --yes vim
To configure Powerline for Vim, add the following lines to your $HOME/.vimrc
file:
python3 from powerline.vim import setup as powerline_setup
python3 powerline_setup()
python3 del powerline_setup
set laststatus=2
The laststatus
setting displays the status bar in Vim and makes Powerline visible by default.
Configure tmux
To configure Powerline in tmux, add the following to your ~/.tmux.conf
file:
set -g default-terminal "screen-256color"
source "/usr/share/powerline/bindings/tmux/powerline.conf"
You must set the correct value for your terminal using the default-terminal
setting. If you don’t configure the correct value for your terminal, you might run into some issues. For example, Vim inside of tmux doesn’t show colored Powerline segments. The screen-256color
or xterm-256color
values work fine in our environments.
Edit your Powerline configuration
You can customize what segments appear in Powerline, or even the behavior of specific segments. Follow these instructions to customize your Powerline installation:
- Copy the
/usr/share/powerline/config_files/
folder to$HOME/.config/powerline
:mkdir -p $HOME/.config/powerline cp -R /usr/share/powerline/config_files/* \ $HOME/.config/powerline/
- Edit the files there according to your needs. A good starting point is the
$HOME/.config/powerline/config.json
file. - Reload the Powerline daemon:
powerline-daemon --replace
The following example shows how to configure Powerline on the shell to behave as the demo shown in the introduction of this guide:
- To show the vcs segment—which displays information about git repositories—on the left side of the shell, replace the default theme with the default_leftonly theme in the
$HOME/.config/powerline/config.json
file:··· "shell": { "colorscheme": "default", "theme": "default_leftonly", "local_themes": { "continuation": "continuation", "select": "select" } }, ···
- To make the vcs segment display in a different color when the git repository is dirty, add the
status_colors
attribute to the vcs segment in the$HOME/.config/powerline/themes/shell/default_leftonly.json
file:··· { "function": "powerline.segments.common.vcs.branch", "priority": 40, "args": { "status_colors": true } } ···