In the first part of this tutorial, we covered the installation and basic configuration of Powerline. While the default setup may suffice for many users, it can feel limiting for others, including myself. Therefore, in this second part, we will dive deeper into customizing Powerline to enhance your terminal experience and make it more visually appealing and enjoyable to use.
This article is sponsored by TUXEDOComputers, a German company that produces Linux hardware, notebooks, computers, and more. Always and forever, all ideas and opinions on this website are wholly mine, as my values are not for sale. To learn more, read our Code of Ethics.{alertInfo}
How to Customize Powerline?
Mainly, Powerline provides three hidden light sources: color schemes, themes, and segments. To uncover them, you should customize the default configuration files.
First of all, before you modify the configuration files headlong, copy them to the home directory.
mkdir -p $HOME/.config/powerline
Ubuntu & Ubuntu-based distros: cp -R /usr/share/powerline/config_files/* $HOME/.config/powerline/Arch & Arch-based distros: cp -R /usr/lib/python3.x/site-packages/powerline/config_files/* $HOME/.config/powerline/ (replace x with the appropriate Python version.){codeBox}
To check the Python version in Linux, you can use the following command in your terminal: python --version{alertInfo}
Color Schemes
Powerline has a colors and gradients dictionary that you should use to customize the color schemes. Since you have copied the configuration files to the home folder, all you have to do is open the dictionary file and the color schemes configuration file to start the color customization operation:- First, go to your home folder using your favorite file manager;
- Show hidden files by clicking Ctrl+H;
- Then, open with your favorite text editor, the colors dictionary, and the color schemes:
- Colors dictionary: ~/.config/powerline/colors.json
- Color schemes configuration file: ~/.config/powerline/colorschemes/default.json
- In some cases, you may need to edit ~/.config/powerline/colorschemes/shell/default.json to change segment colors, such as the hostname segment.
- Now, to change the username background color, pick up a color from the dictionary (darkred, for example), assign it to bg of the user group in the color schemes config file.
- Save the change, then reload Powerline to activate the change using the following command line:
powerline-daemon --replace{codeBox}
- To change the current working directory background color, assign your picked color to bg on the information:regular group.
- To change the font color, assign your selected color to fg instead.
If you do not want to tamper with the default settings file, you can create a new configuration file with a name of your choice and then modify it. To achieve this:
- Duplicate (copy & paste) the default file (.config/powerline/colors.json), rename the replica, modify it, and save the changes;
- Open the Powerline config file, assign the new file name to shell color schemes, and reload Powerline to activate the change.{alertWarning}
Themes
Theme (name) |
Description |
---|---|
powerline | Default powerline theme with fancy powerline symbols. |
unicode_terminus |
Theme containing only symbols from terminus PCF font. |
powerline_unicode7 | Theme with powerline dividers and unicode-7 symbols. |
unicode | Theme without any symbols from private use area. |
powerline_terminus | Like unicode_terminus, but with powerline symbols. |
unicode_terminus_condensed | Like unicode_terminus, but occupies as less space as possible. |
ascii | Theme without any unicode characters at all. |
If you decide to use one of the terminus-related top themes, make sure that you install the terminus font.{alertWarning}
- Open the Powerline config file: ~/.config/powerline/config.json
- Go to the shell options group and add the top_theme string (code) as follows:
"shell": {
"colorscheme": "linuxtechmore",
"theme": "default_leftonly",
"top_theme": "name",
"local_themes": {
"continuation": "continuation",
"select": "select"
}{codeBox}
- Save the change and reload Powerline.
powerline-daemon --replace{codeBox}
By default, Powerline uses the default_leftonly theme for the shell, which only utilizes the left side of the prompt. For a more informative prompt that uses both the left and right sides, I recommend switching to the default theme.{alertInfo}
Segments
Segment | Description |
---|---|
VCS submodule |
displays information about the current VCS (version control systems) branch (git repositories) and stash entries. |
System properties |
displays various system information such as uptime & load average. |
Network | displays network-related information: external IP address, current hostname (net), internal IP address, and network load. |
Current environment |
displays information about environment variables such as the current working directory and current user name. |
Battery | displays the battery status. |
Weather | displays weather conditions using Yahoo! Weather provider. |
Date and time |
displays the current date/time. |
display an alert for new emails using IMAP. |
To add one of the segments described above, it's essential to understand the functions and parameters (definitions) of each segment so you can correctly edit the configuration file.
By default, the following segments are enabled in the default Powerline shell theme: On the left side: Hostname, User environment, Virtual environment, Current working directory, Job number. On the right side: Last pipe status, Git stash status, Git branch. You can adjust and tweak them using their appropriate arguments.{alertWarning}
VCS submodule
- VCS Branch
{"function": "powerline.segments.common.vcs.branch",
"priority": value (e.g., 10, 20, 30, 40),
"args": {
"status_colors": true or false,
"ignore_statuses": ["U"]
}
}
{codeBox}
- priority: In Powerline, the priority parameter determines segment order. Lower priority segments display first, while higher ones may be omitted if space is limited. Example: 10.
- status_colors: If true, colors the branch name based on the VCS status.
- ignore_statuses: (list) List of statuses to ignore. For example, ["U"] to ignore untracked files.
- VCS Stash
{
"function": "powerline.segments.common.vcs.stash",
"priority": value
}{codeBox}
System properties
- Uptime
{
"function": "powerline.segments.common.sys.uptime",
"priority": value,
"args": {
"shorten_len": integer
}
}{codeBox}
- shorten_len: (integer) Shorten the uptime display to this number of characters. Example: 5.
- Load Average
It shows the average number of processes that are either in a runnable or uninterruptible state. This is a measure of system demand and is typically used to assess how busy the system is.
{
"function": "powerline.segments.common.sys.system_load",
"priority": 20,
"args": {
"short": true or false,
"track_cpu_count": false or true,
"threshold_bad": float,
"threshold_good": float,
"format": "string"
}
}{codeBox}
Thresholds arguments support decimals (floats) to deal with continuous values.. Integers are stuck with whole numbers.{alertInfo}
- short (default: false): true to display only the 1-minute load average, false to display the full load average (1, 5, and 15-minute intervals).
- track_cpu_count (default: false): true to adjust thresholds based on CPU count, false for static thresholds.
- threshold_bad (default: 2): Load average above this is considered bad. Example: 2.5.
- threshold_good (default: 1): Load average below this is considered good. Example: 1.5.
- format: Display format (default: "CPU {avg:.1f}" for one decimal place).
Double quotes (") are necessary to define strings within the Powerline configuration file. Removing them can lead to errors in your Powerline prompt.{alertWarning}
- CPU load as a percentage
{
"function": "powerline.segments.common.sys.cpu_load_percent",
"priority": 20,
"args": {
"interval": integer,
"format": "CPU {0:.0f}%",
"update_first": true or false
}
}{codeBox}
- interval (default: 1): The time in seconds between updates. Example: 2.
- format: Display format for CPU load percentage. In this case, "{0:.0f}%" will show the load as a whole number percentage without decimal places.
- update_first: If true, update the segment immediately when Powerline starts, rather than waiting for the first interval (default: true).
Network
- Hostname
{
"function": "powerline.segments.common.net.hostname",
"priority": value,
"args": {
"only_if_ssh": true or false
}
}
{codeBox}
- only_if_ssh: If true, the hostname will only be displayed when connected via SSH (Default is true).
- Network Load
{
"function": "powerline.segments.common.net.network_load",
"priority": value,
"args": {
"interval": value,"update_first": true or false,
"interface": "string",
"si_prefix": true or false,
"suffix": "string",
"recv_format": "string",
"sent_format": "string"
}
}
{codeBox}
- interval: The interval in seconds between updates, eg., 1.
- update_first: if true, update the segment immediately upon startup.
- interface: The network interface to monitor, e.g., "eth0", "wlo1".
For a quick overview of network interfaces in Linux, use the ip link show command.{alertInfo}
- si_prefix: if true, use SI prefixes (KB, MB, etc.) instead of binary prefixes (KiB, MiB, etc.).
- suffix: A string to append to the data rate (e.g., "B/s " for bytes per second).
- recv_format: (string) Format string for received data, e.g., "DL {value:>8}".
- sent_format: (string) Format string for sent data, e.g., "UL {value:>8}".
- Internal IP Address
{
"function": "powerline.segments.common.net.internal_ip",
"priority": value,
"args": {
"interface": "string",
"ipv": "integer"
}
}{codeBox}
- interface: The network interface for which you want to display the internal IP address, e.g., "eth0", "wlan0".
- ipv: (integer) The IP version to display. This can be either 4 for IPv4 or 6 for IPv6.
- External IP Address
{
"function": "powerline.segments.common.net.external_ip",
"args": {
"interval": value,
"query_url": "string",
}
}{codeBox}
- interval: The interval in seconds between updates. Example: 600.
- "query_url": This argument specifies the web address (URL) from which the segment retrieves your external IP address. The default URL "http://ipv4.icanhazip.com/" is a reliable option specifically designed for this purpose.
Current environment
- Current Working Directory
{
"function": "powerline.segments.common.env.cwd",
"priority": value,
"args": {
"dir_shorten_len": "integer",
"dir_limit_depth": "integer",
"use_path_separator": true or false
}
}{codeBox}
- dir_shorten_len: The length to which the directories should be shortened. Example: 3 (directories will be shortened to the first 3 characters).
- dir_limit_depth: The maximum depth of directories to display. Example: 2 (only the last two directories will be displayed).
- use_path_separator: Whether to use a path separator (/) in the display. Example: true (use the path separator).
- Current User Name
{
"function": "powerline.segments.common.env.user",
"priority": value,
"args": {
"hide_domain": true or false,
"hide_user": "username"
}
}{codeBox}
- Hide domain: Set "hide_domain": true to show only the username without the domain part.
- Hide username: Set "hide_user": "a username" (not recommended) to hide the username completely. Leaving it as None (default) ensures the username is displayed based on the "hide_domain" setting.
- Virtual Environment
{
"function": "powerline.segments.common.env.virtualenv",
"priority": value,
"args": {
"ignore_conda": true or false,
"ignore_venv": true or false
}
}{codeBox}
- "ignore_conda": (default: false) Shows the virtual environment name even if it's a Conda environment. Set to true to hide Conda names.
- "ignore_venv": (default: false) Shows the virtual environment name even if it's a standard venv environment. Set to true to hide venv names.
The powerline.segments.common.env.virtualenv segment will only show information if you're currently within a Python or Conda virtual environment.{alertWarning}
Battery
{
"function": "powerline.segments.common.bat.battery",
"priority": value,
"args": {
"offline": "string",
"online": "string",
"empty_heart": "string",
"full_heart": "string",
"gamify": true or false,
"steps": integer,
"format": "string"
}
}{codeBox}
- offline: Character to display when the battery is offline (not charging). Example: "🔋".
- online: Character to display when the battery is online (charging). Example: "⚡︎".
- empty_heart: Character to display when the battery is empty. Example: "♡".
- full_heart: Character to display when the battery is full. Example: "♥".
- gamify: If true, displays the battery status in a gamified manner (hearts).
- steps (default: 5): This argument is only relevant when gamify is set to true. It defines the total number of symbols used to represent the entire battery level range (0-100%).
- format: format string for displaying the battery state and capacity. {ac_state} represents the charging state, and {capacity:3.0%} represents the battery capacity as a percentage. The 3.0% format ensures the battery percentage is displayed with three decimal places and a percent symbol. Example: "format": "{ac_state} {capacity:3.0%}".
Weather
{
"function": "powerline.segments.common.wthr.weather",
"priority": 50,
"args": {
"interval": value,
"update_first": true or false,
"location_query": "string",
"temp_hottest": 40,
"temp_coldest": -20,
"unit": "C"
}
}{codeBox}
- interval: How often to update the weather information (in seconds), e.g., 600.
- update_first: Whether to fetch the weather information immediately when the segment is loaded.
- location_query: The location for which to display the weather, e.g., "gaza, palestine".
- temp_hottest: The temperature considered "hot" for color coding. Example: 40.
- temp_coldest: The temperature considered "cold" for color coding. Example: -20.
- units: (string) The unit for temperature, e.g., "C" (Celsius) or "F" (Fahrenheit).
Date & time
{
"function": "powerline.segments.common.time.date",
"priority": value,
"args": {
"format": "string"
}
}{codeBox}
- format: The format string for the date/time, e.g., "%Y-%m-%d %H:%M:%S".
Now that you have learned about the common Powerline segments and their arguments, you can enable your desired segment by following these steps:
- Open the relevant configuration file, such as ~/.config/powerline/themes/shell/default.json, using a text editor;
- Insert the segment definition within the appropriate placement (e.g., "left" or "right"):
Adding the Weather segment |
Make sure to add a comma (,) after the previous segment's closing curly brace (}) before adding another segment {alertWarning}
{
"function": "powerline.segments.common.wthr.weather",
"priority": 50,
"args": {
"interval": 600,
"update_first": true,
"location_query": "gaza, palestine",
"temp_hottest": 50,
"temp_coldest": -30,
"unit": "C"
}
}
{codeBox}
- After making changes, save the configuration file and reload Powerline to apply the changes. Use the following command to reload Powerline:
powerline-daemon --replace{codeBox}
Enhancing Segments with Highlight Groups
Powerline allows customization through highlight groups, which control the appearance of segments by defining colors, gradients, and other attributes. Each segment can be associated with one or more highlight groups to define its look:
- battery Segment:
"highlight_groups": ["battery", "battery_gradient", "battery_full", "battery_empty"]{codeBox}
- user Segment:
"highlight_groups": ["user"]{codeBox}
- network_load Segment:
"highlight_groups": ["network_load", "network_load_gradient", "network_load_sent_gradient", "network_load_recv_gradient", "network_load:divider"]{codeBox}
- hostname Segment:
"highlight_groups": ["hostname"]{codeBox}
- cpu_load_percent Segment:
"highlight_groups": ["cpu_load_percent", "cpu_load_percent_gradient"]{codeBox}
- system_load Segment:
"highlight_groups": ["system_load", "system_load_gradient"]{codeBox}
- weather Segment:
"highlight_groups": ["weather", "weather_temp_gradient", "weather_condition_hot", "weather_condition_snowy", "weather_condition_rainy"]{codeBox}
- cwd Segment:
"highlight_groups": ["cwd", "cwd:current_folder", "cwd:divider"]{codeBox}
- branch Segment:
"highlight_groups": ["branch", "branch_dirty", "branch_clean", "branch:divider"]{codeBox}
- stash Segment:
"highlight_groups": ["stash", "stash:divider"]{codeBox}
- virtualenv Segment:
"highlight_groups": ["virtualenv"]{codeBox}
- uptime Segment:
"highlight_groups": ["uptime"]{codeBox}
To add a segment with its highlight groups, you can structure it as follows:
{
"function": "powerline.segments.common.wthr.weather",
"priority": 50,
"highlight_group": "weather_temp_gradient",
"args": {
"interval": 600,
"update_first": true,
"location_query": "gaza, palestine",
"temp_hottest": 40,
"temp_coldest": -20,
"unit": "C"
}
}{codeBox}
With this configuration, the weather segment will be associated with the "weather_temp_gradient" highlight group, ensuring it adheres to the defined color scheme or styling for that group.
In conclusion, I hope this humble tutorial has helped illuminate the darkness of your terminal. Remember to explore the various options and configurations Powerline offers, and don't hesitate to experiment to find what works best for you. Feel free to share your Powerline setup in the comments below!
At Linux-Tech&More, I'm committed to providing you with an adsense-free (and automated ads-free) reading experience. I believe in delivering uninterrupted and user-focused content. If you enjoy my blog and would like to show your support, you can do so via
Your support makes a difference!{alertIdea}