Skip to content

Instantly share code, notes, and snippets.

@Tset-Noitamotua
Last active March 14, 2023 13:35
Show Gist options
  • Save Tset-Noitamotua/1fd436011ff91b5336ce34b783902fbd to your computer and use it in GitHub Desktop.
Save Tset-Noitamotua/1fd436011ff91b5336ce34b783902fbd to your computer and use it in GitHub Desktop.
How to install and configure Powerline on Linux (Deepin Linux 15.7, Debian / Ubuntu) with git status?

(Dead) simple installation / configuration of Powerline (powerline-status)

#Linux #bash #git #Powerline

If you ever have to reinstall Powerline on another machine this are the easy steps to follow to give you a nice looking prompt with git status and branch name in your bash terminal. Steps where done on Deepin Linux 15.7 but should also work on Debian / Ubuntu.

image - Deepin Linux Bash Powerline Git Status

TL;DR

pip install powerline-status

wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf
wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf

# NOTE: adjust fonts paths properly!
mv PowerlineSymbols.otf /usr/share/fonts/

fc-cache -vf /usr/share/fonts/

mv 10-powerline-symbols.conf ~/.config/fontconfig/conf.d/

# add this to your .bashrc
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. {powerline-installation-dir}/bindings/bash/powerline.sh
# NOTE: use `pip show powerline-status` to find your **{powerline-installation-dir}**

mkdir -p ~/.config/powerline
# NOTE: adjust your {powerline-installation-dir} properly!
cp /{powerline-installation-dir}/config_files/config.json ~/.config/powerline

# edit ~/.config/powerline/config.json to see git branch name in prompt
# --> "theme": "default_leftonly",

# edit /{powerline-installation-dir}/segments/common/vcs.py to color highlight git status (sudo?)
# --> def __call__(self, pl, segment_info, create_watcher, status_colors=True, ignore_statuses=()):
# optionally set "ignore_statuses=()" to "ignore_statuses=(["U"])" to ignore untracked files

powerline-daemon --replace

# close all terminal windows
# FINISH

NOTE: If you run into issues scroll down and check my latest comments - hope it helps ♥

DETAILED INSTRUCTIONS (10 STEPS)

How to install Powerline in 10 steps on Linux and configure it for bash terminal with git status.

  1. pip install powerline-status

Fonts installation

Download fonts file and fontconfig file.

  1. wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf
    wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf

Move the symbol font to a valid X fonts path. Valid fonts paths can be listed with xset q (--> Font Path: ...).

  1. # NOTE: adjust fonts path properly!
    mv PowerlineSymbols.otf /usr/share/fonts/

Update fonts cache.

  1. # NOTE: adjust fonts path properly!
    fc-cache -vf /usr/share/fonts/

Install fontconfig.

  1. mv 10-powerline-symbols.conf ~/.config/fontconfig/conf.d/

Edit your .bashrc

Add this lines to your .bashrc

  1. powerline-daemon -q
    POWERLINE_BASH_CONTINUATION=1
    POWERLINE_BASH_SELECT=1
    . {powerline-installation-dir}/bindings/bash/powerline.sh

NOTE: use pip show powerline-status to determine your {powerline-installation-dir} (e.g. Location: /usr/local/...)

Customization (show git status and branch name)

  1. mkdir -p ~/.config/powerline

Copy config.json from {powerline-installation-dir}/config_files/ to ~/.config/powerline

  1. # NOTE: adjust your {powerline-installation-dir} properly!
    cp /usr/lib/python3.6/site-packages/powerline/config_files/config.json ~/.config/powerline

To see git branch name and color highlighted git status in prompt you have to

  • change shell/theme property from default to default_left_only in ~/.config/powerline/config.json (see 9.)
  • copy default_leftonly.json to your user config directory (~/.config/powerline) and modify it (see 10.).
  1. # edit ~/.config/powerline/config.json
    {
      ...
    	"ext": {
        ...
    		"shell": {
    			"colorscheme": "default",
    			"theme": "default_leftonly",
    			"local_themes": {
    				"continuation": "continuation",
    				"select": "select"
    			}
    		},
        ...
    	}
    }
  2. # copy default_leftonly.json from powerline installation dir to user config dir
    cp {powerline-installation-dir}/config_files/themes/shell/default_leftonly.json ~/.config/powerline
    
    # modify default_leftonly.json in user config dir
    nano ~/.config/powerline/default_leftonly.json
    {
           "function": "powerline.segments.common.vcs.branch",
           "priority": 40,
           "args": {
                       "status_colors": true,
                       "ignore_statuses": ["U"]
                   }
    },

FINISH! APPLY CHANGES!

Your changes will not apply until you restart the daemon

powerline-daemon --replace

Need even more details? --> Official Documentation

@Tset-Noitamotua
Copy link
Author

Tset-Noitamotua commented Jan 13, 2019

Some ideas came from this post powerline/powerline#186

Liked this one a lot

mkdir -p ~/.config/powerline
cat <<-'EOF' > ~/.config/powerline/config.json
{
    "ext": {
        "shell": {
            "theme": "default_leftonly"
        }
    }
}
EOF
powerline-daemon --replace

@sebastien-prudhomme
Copy link

FYI you don't need ti patch Python source code. Copy default_leftonly.json in your user config directory and modify it:

                        {
                                "function": "powerline.segments.common.vcs.branch",
                                "priority": 40,
                                "args": {
                                        "status_colors": true,
                                        "ignore_statuses": ["U"]
                                }
                        },

@Tset-Noitamotua
Copy link
Author

FYI you don't need ti patch Python source code. Copy default_leftonly.json in your user config directory and modify it:

Thanks, will try this soon cause my powerline-prompt is broken since update from Deepin 15.7 to 15.10 :)

@Tset-Noitamotua
Copy link
Author

Tset-Noitamotua commented Aug 11, 2019

damn ... have trouble with fonts since update of Deepin 😭

looks like shit
image

Here's some fonts related docs from Deepin Wiki

@Tset-Noitamotua
Copy link
Author

ok ... not sure what went wrong before but in the end this is what brought my nice powerline back:

you can copy/paste that into console (with comments, commands will be executed in sequence)

# source: https://github.com/powerline/fonts
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts
fc-cache -vf
powerline-daemon --replace

# close and reopen console
# FINISH

in case I need this one day - some fonts related paths in Deepin Linux:

  • /etc/fonts/
  • /etc/fonts/conf.d
  • /etc/fonts/conf.d/README !!!
  • /usr/share/fontconfig/
  • /usr/share/fonts/

@Tset-Noitamotua
Copy link
Author

FYI you don't need ti patch Python source code. Copy default_leftonly.json in your user config directory and modify it:

                        {
                                "function": "powerline.segments.common.vcs.branch",
                                "priority": 40,
                                "args": {
                                        "status_colors": true,
                                        "ignore_statuses": ["U"]
                                }
                        },

For some reason this does not work for me. So here is my old solution for that which works:

	# edit /{powerline-installation-dir}/segments/common/vcs.py (may require sudo)
        # in this line
        def __call__(self, pl, segment_info, create_watcher, status_colors=False, ignore_statuses=()):
        # change:  status_colors=False --> status_colors=True
	# change: ignore_statuses=() --> ignore_statuses=(["U"])             to ignore untracked files
        # so that the result looks like this	
	def __call__(self, pl, segment_info, create_watcher, status_colors=True, ignore_statuses=(["U"])):

@r1cs3c
Copy link

r1cs3c commented Nov 19, 2020

I am using Kali Linux and I got it to work after I changed the .bashrc code to look like:

export PATH=$PATH:/home/$(users)/.local/bin/

# Powerline initialisation code
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. {powerline-installation-dir}/bindings/bash/powerline.sh

@aravindnadumane
Copy link

Sorry this is definately not "Dead simple"

you say:

. {powerline-installation-dir}/bindings/bash/powerline.sh

...
# copy default_leftonly.json from powerline installation dir to user config dir
cp {powerline-installation-dir}/config_files/themes/shell/default_leftonly.json ~/.config/powerline

NOTE: use pip show powerline-status to determine your {powerline-installation-dir} (e.g. Location: /usr/local/...)

well:

pi@raspberrypi:~ $  pip show powerline-status
Name: powerline-status
Version: 2.8.1
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: /usr/lib/python3/dist-packages
Requires:
Required-by:

and

ll /usr/lib/python3/dist-packages/powerline/bindings/
total 48
drwxr-xr-x  9 root  4096 May 19 08:02 ./
drwxr-xr-x 13 root  4096 May 19 08:02 ../
-rw-r--r--  1 root 10072 May 20  2020 config.py
-rw-r--r--  1 root     0 May 20  2020 __init__.py
drwxr-xr-x  3 root  4096 May 19 08:02 ipython/
drwxr-xr-x  3 root  4096 May 19 08:02 pdb/
drwxr-xr-x  2 root  4096 May 19 08:02 __pycache__/
drwxr-xr-x  3 root  4096 May 19 08:02 tmux/
drwxr-xr-x  3 root  4096 May 19 08:02 vim/
drwxr-xr-x  3 root  4096 May 19 08:02 wm/
drwxr-xr-x  3 root  4096 May 19 08:02 zsh/

now where is your {powerline-installation-dir}/bindings/bash/powerline.sh?
{powerline-installation-dir}/config_files/themes/shell/default_leftonly.json is not to be found!
also /{powerline-installation-dir}/config_files/config.json file is not existing!

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