Powerline secrets

You know that XKCD comic where the protagonist googles a tech question and the only matching result is from a long dead thread or even forum that details the issue but provides no answers? I am wondering if other people sometimes happen on the subcategory of that where the thread originator instead of being DenverCoder9 is… yourself. Instead of “closeness to another soul”, it just engenders a slight disappointment. Right, I’ve been here before, trying the same thing and given up.

Trying to customize my powerline setup raised a number of questions that I could not find answers to in the official documentation, including the question of whether root’s bash prompt could be coloured anything other than fire engine red. Luckily I found answers to all of these this time round.

How do I change root’s prompt background color?

For ordinary users changing the background color of the bash prompt is easy. Copy the default colorscheme file into your powerline configuration’s colorschemes subdirectory and edit the user line (the bg setting controls background color). This doesn’t work for root because powerline makes a hardcoded exemption for the user with UID 0. I would be remiss not to point out that this is probably a sensible safety measure: You should always be very aware when you’re root. Red is fine, but can we please adopt a less aggressive red?

To allow standard user configuration for root, simply change the line in

(note: the path before 'powerline' varies with distros and python versions - if you installed with pip, run 'pip3 show powerline-status' to see where it is)

where the user’s id is tested, i.e. euid != 0. Change the zero to a different UID that nobody uses, say 66666, and root passes the test similar to any other user. Needless to say, this change will be overwritten with updates so either be prepared to redo it or fork and patch.

Why does my hostname sometimes show up in the prompt?

A padlock and a hostname on a bright orange background would form part of my user’s prompt whenever I ssh’ed into my VPS. Not on my desktop or laptop, or when I su’ed to root or another user. The inconsistency more than the segment was what annoyed me. And seeing as the hostname was visible in two different places in my tmux setup, it felt unnecessary to have it repeated a third time with every command. Turns out powerline looks for the environment variable SSH_CLIENT. If this is set, a hostname segment is added to the default shell prompt theme. The setting can be found in the file


Fortunately there is an alternative to changing the code here, namely using any shell theme, that is not “default”. Copy the file default.json from the same folder as above to your own shell theme folder (usually ~/.config/powerline/themes/shell), rename it to something else (best change the name of the file and the name setting in the file) and set the shell theme to your new custom theme in your config.json file.

How do I match/change the powerline-tmux background color?

I tried changing it using some suggestions from this issue on github but to no avail. So I just accepted it, took a screenshot and used the GIMP to identify the color code. It’s “121212”. Then I added it colors.json as “default_bg” and reused it whenever I wanted the same shade in other powerline segments.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.