Skip to content

Instantly share code, notes, and snippets.

@mattsizzle
Last active February 2, 2023 11:49
Show Gist options
  • Save mattsizzle/6dc0b924c6a65ad2e1e036002bdc1b15 to your computer and use it in GitHub Desktop.
Save mattsizzle/6dc0b924c6a65ad2e1e036002bdc1b15 to your computer and use it in GitHub Desktop.
Powerline Configuration (Debian 11 optionally with GIT support)

Powerline Configuration (Debian/Ubuntu/PopOS optionally with GIT support)

Powerline

Powerline is a statusline plugin for vim, and provides status lines and prompts for several other applications, including zsh, bash, fish, tmux, IPython, Awesome, i3, and Qtile.

In other words, it is a very powerful and very cool piece of software, and I use it in some capacity on all my servers. It can be installed a few ways with binaries available in most distro's main repositories and many derivatives available. I prefer the Python userspace installation method outlined below as it lends itself to portability and works better with my virtualization practices.

Notes

I install and configure the Fonts which some people are pretty opinionated about ¯\(ツ)/¯, but if you configure powerline without symbols you won't need them

I also use the Solarized color palette across all my environments which require the additional colorschemes/solarized.json to be copied and modified, but I omitted this step below. It follows the same instructions for copying and modifying as the other files.

Installation

Assuming a new(ish) Debian installation pip might not be installed. If so install it.

sudo apt install python3-pip

powerline is written in Python so we will install it via pip for the user. This keeps the base system python unaltered and as it is sourced in the user's .bashrc a venv adds too much complexity.

pip3 install --user powerline-status

Once installed we need to set up the bash profile to load the daemon and run the shell configure script. I normally do this in the ~/.bashrc file of the user we installed powerline-status as.

Locate the installation path using pip:

pip list # shows all installation packages for that environment (user)
pip show powerline-status

Expected Output:

user@hostname:~$ pip show powerline-status

Name: powerline-status

Version: 2.7 Summary: The ultimate statusline/prompt utility.

Home-page: https://github.com/powerline/powerline

Author: Kim Silkebaekken

Author-email: kim.silkebaekken+vim@gmail.com

License: MIT

Location: /home/user/.local/lib/python3.9/site-packages

Requires:

Required-by:

The location line shows the install path. Using that update your ~/.bashrc to match the following replacing the POWERLINE_PATH location with the one returned with the pip show powerline-status from above.

NOTE: The local executables line allows you to call powerline-daemon from the command line. e.x. $ powerline-daemon --replace to reload the powerline daemon with a new configuration.

# Local executables
export PATH=$PATH:$HOME/.local/bin

# Powerline configuration
export POWERLINE_PATH=$HOME/.local/lib/python3.9/site-packages/powerline
if [ -f $POWERLINE_PATH/bindings/bash/powerline.sh ]; then
    $HOME/.local/bin/powerline-daemon -q
    POWERLINE_BASH_CONTINUATION=1
    POWERLINE_BASH_SELECT=1
    source $POWERLINE_PATH/bindings/bash/powerline.sh
fi

Once this is saved in the .bashrc file you can run $ source ~/.bashrc to start powerline and your prompt should update. You can also close the terminal and open a new one to achieve the same effect.

Install Powerline Fonts

Powerline uses symbols in many of the prompt configurations which will appear as without an appropriate font installed. To install the compatible fonts do the following:

cd /tmp && git clone https://github.com/powerline/fonts.git --depth=1 fonts && ./fonts/install.sh && cd ~

The command should output the following:

Powerline fonts installed to /home/matt/.local/share/fonts

Configuring Terminal with Powerline Compatible Fonts

Now that the fonts are installed we can configure any terminal emulator on the system to use the new fonts. Note: you will want to ensure the terminal you are updating has been configured to use 256 color. This can be confirmed with:

echo $TERM

xterm-256color

Once confirmed most terminals can be configured by right-clicking the open terminal window and selecting Preferences, navigating to the font selection, and selecting a font that includes for powerline in the name.

Configure Powerline for Current User

The powerline configuration files are stored at POWERLINE_PATH/config_files (forehead_tap.gif** Environment variables make life much easier). I normally only override the ones I am going to modify by copying them to the user's local configuration directory as follows:

Create a new powerline configuration directory.

mkdir -p ~/.config/powerline/{colorschemes,themes,themes/shell}

Copy the configuration files we are going to modify:

cp $POWERLINE_PATH/config_files/colorschemes/default.json ~/.config/powerline/colorschemes/default.json    

cp $POWERLINE_PATH/config_files/themes/shell/default.json  ~/.config/powerline/themes/shell/default.json

Once copied modifying these files (or any other files you need to move and modify such as those for VIM) and reloading the powerline daemon with $ powerline-daemon --replace will update your terminal prompt. $ powerline-lint can be used before running that command to verify the changes will not break to prompt.

Outside of adding GIT support this covers installing and configuring powerline. Hack away at it and make a prompt that would impress even Acidburn.

Hell breaking your terminal prompt and having to drop into a different terminal to fix it is a right of passage every Linux user must and inevitable will pass through.

Optionally Add GIT support

If you use Git the following powerline segment adds information when within a Git repository into the prompt, which is very handy. Git itself offers the abilty to append the prompt which I used before powerline, but powerline makes things much easier with color and symbol support.

powerline-gitstatus

Installing powerline-gitstatus

pip3 install --user powerline-gitstatus

Configuring powerline-gitstatus

Once installed the following definition needs to be added to the color schemes used in various terminal emulators that you want Git support enabled. Typically the $HOME/.config/powerline/colorschemes/default.json at the bottom of the groups section.

"gitstatus":                 { "fg": "gray8",           "bg": "gray2", "attrs": [] },
"gitstatus_branch":          { "fg": "gray8",           "bg": "gray2", "attrs": [] },
"gitstatus_branch_clean":    { "fg": "green",           "bg": "gray2", "attrs": [] },
"gitstatus_branch_dirty":    { "fg": "gray8",           "bg": "gray2", "attrs": [] },
"gitstatus_branch_detached": { "fg": "mediumpurple",    "bg": "gray2", "attrs": [] },
"gitstatus_tag":             { "fg": "darkcyan",        "bg": "gray2", "attrs": [] },
"gitstatus_behind":          { "fg": "gray10",          "bg": "gray2", "attrs": [] },
"gitstatus_ahead":           { "fg": "gray10",          "bg": "gray2", "attrs": [] },
"gitstatus_staged":          { "fg": "green",           "bg": "gray2", "attrs": [] },
"gitstatus_unmerged":        { "fg": "brightred",       "bg": "gray2", "attrs": [] },
"gitstatus_changed":         { "fg": "mediumorange",    "bg": "gray2", "attrs": [] },
"gitstatus_untracked":       { "fg": "brightestorange", "bg": "gray2", "attrs": [] },
"gitstatus_stashed":         { "fg": "darkblue",        "bg": "gray2", "attrs": [] },
"gitstatus:divider":         { "fg": "gray8",           "bg": "gray2", "attrs": [] }

After this is added you can add the segment at $HOME/.config/powerline/themes/shell/default.json in the appropriate segments section.

{
        "function": "powerline_gitstatus.gitstatus",
        "priority": 40
}

This is the default configuration and can be modified as needed. Updating the priority can for instance move the git information further left on the prompt. Updating the color schema fg value will change that segment's color and so forth. It is probably a good idea at this point to run $ powerline-lint. If you receive an error such as the following:

found highlight group gitstatus not defined in the following colorschemes: solarized

You will need to update the associated colorscheme config JSON file as the theme config will require the segment to be present for all colorschemes.

Modifying powerline-gitstatus Segments

I also copy the $POWERLINE_PATH/config_files/themes/shell/__main__.json file into $HOME/.config/powerline/themes/shell/__main__.json and add the following under the segment_data section

"gitstatus": {
        "args": {
            "formats": {
                    "branch": "\ue0a0 {}",
                    "tag": " ★ {}",
                    "behind": " ↓ {}",
                    "ahead": " ↑ {}",
                    "staged": " ● {}",
                    "unmerged": " ✖ {}",
                    "changed": " ✚ {}",
                    "untracked": " … {}",
                    "stashed": " ⚑ {}"
            }
        }
},

While this is not necessary, it does allow you to for example remove symbols that are not included in your current terminals font.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment