Powerline for Bash
Powerline for Bash
Powerline for Bash
(Tested on Ubuntu 19.10, 20.04)
Since Powerline is provided via pip, the first step is to install pip3 if we do not already have it on our system.
Install pip3:
sudo apt install python3-pip
Install Powerline:
pip3 install --user powerline-status
````
Start powerline by adding it to `~/.bashrc` file:
```bash
# Add this to your PATH if it’s not already declared
export PATH=$PATH:$HOME/.local/bin
# Powerline configuration
if [ -f $HOME/.local/lib/python3.8/site-packages/powerline/bindings/bash/powerline.sh ]; then
$HOME/.local/bin/powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
source $HOME/.local/lib/python3.8/site-packages/powerline/bindings/bash/powerline.sh
fi
With this configuration, when starting a new terminal we will already see Powerline popping up. Unfortunately, this does not yet show any git related information when changing your location into a git repository. To make Powerline working with git as described, there is something more we need to do.
Installing Powerline Gitstatus:
pip3 install powerline-gitstatus
Open the following file and add the lines after the “attached_clients” entry:
~/.local/lib/python3.8/site-packages/powerline/config_files/colorschemes/default.json
"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": [] }
~/.local/lib/python3.8/site-packages/powerline/config_files/themes/shell/default.json
Change line from:
"function": "powerline.segments.shell.jobnum",
"priority": 20
To:
"function": "powerline_gitstatus.gitstatus",
"priority": 40
Finally, we need to install the Powerline font enabling our shell to show all the special characters and icons correctly.
Go to your Download directory and clone the Powerline font git repository and install the fonts:
cd ~/Downloads
git clone https://github.com/powerline/fonts.git --depth=1 fonts
./fonts/install.sh
To use the newly installed fonts in the terminal open preferences and open the selected profile. Check “custom font” and change the font to “Source Code Pro for Powerline Regular”.
Since we have updated the files in the main directory, we can copy the configurations to the user’s home to ensure that the configuration persists even when update change things in the background.
To do so generate the directory structure in the user’s home:
mkdir ~/.config/powerline
mkdir ~/.config/powerline/colorschemes
mkdir ~/.config/powerline/themes
mkdir ~/.config/powerline/themes/shell
And copy the configuration files:
cp ~/.local/lib/python3.8/site-packages/powerline/config_files/colorschemes/default.json ~/.config/powerline/colorschemes/
cp ~/.local/lib/python3.8/site-packages/powerline/config_files/themes/shell/default.json ~/.config/powerline/themes/shell/
Visual Studio Code
Since, I am using Visual Studio Code, I did recognize that Powerline does not out of the box display properly in the integrated terminal. To improve this behaviour, the settings for the integrated terminal should also be changed:
Terminal Integrated Font Family → Source Code Pro for Powerline