Change Linux terminal color scheme based on wallpaper

0

If you’re a subscriber to the It’s FOSS newsletter, you already know that we’ve launched a new “Terminal Tuesday” series. In this document, you will discover command line tools or tips/tricks to help you in the terminal.

Terminal isn’t just serious work, it can be fun sometimes. You can play games in the terminal or use fun Linux commands to amuse yourself, your colleagues or your family members.

This week’s final tip is fun. It’s about changing your terminal’s color palette to match your desktop background.

Why would you do that? Because it looks good and if you share your Linux desktop screen, it adds a nice touch to the overall look.

Pywal: Handy utility to automatically change Linux terminal scheme based on wallpaper

Pywal is a nifty Python-based command-line tool that changes terminal colors based on desktop background colors.

You can use it to set the wallpaper and you will see that the terminal colors change immediately.

Look at this. Sounds good, doesn’t it?

Let me show you how to use Pywal correctly.

Step 1: Install Pywal on Linux

Pywal is Python-based, so you can easily install it on any Linux distribution that supports Python. It’s even easier for Arch/Manjaro users because they can find python-pywal package in their repository.

First you will need to install Pip. You can use your distro’s package manager to install pip3 (for Python3). On Debian/Ubuntu based distributions, you can use the following command:

sudo apt install python3-pip

Now that you have pip3 on your system, use it to install Pywal for all users on your system:

sudo pip3 install pywal

Step 2: Use Pywal to change the terminal color scheme

I assume you are somewhat familiar with Linux commands to use Pywal.

Download the wallpaper of your choice. Note the location of the wallpaper and its file name.

Open a terminal and use the wal command with the location of your wallpaper file as input:

wal -i path_to_wallpaper_file

You will see that your system background is changed and the terminal immediately changes color according to the wallpaper:

Pywal Linux terminal color scheme

Step 3: Make the new terminal use the wallpaper color scheme

Open a new terminal and you’ll notice that it doesn’t use the new color scheme.

Weird? Not really. By default, the changed color scheme only applies to terminal screens that are already running. Newly opened terminals continue to use the system color scheme.

This can be changed easily. You can use modify your shell configuration file.

Normally you should use the bash shell but if you are unsure check which shell you are using by default.

Open the ~/.bashrc file in your favorite terminal-based text editor. On Ubuntu you can still use the nano editor.

At the end of this ~/.bashrc file, add the following line, save and exit the file.

# Import colorscheme from 'wal' asynchronously
# &   # Run the process in the background.
# ( ) # Hide shell job control messages.
(cat ~/.cache/wal/sequences &)

# Alternative (blocks terminal for 0-3ms)
cat ~/.cache/wal/sequences

# To add support for TTYs this line can be optionally added.
source ~/.cache/wal/colors-tty.sh

From now on, the new color scheme will also be applied to new terminals.

Step 4: Keep new color scheme even after reboot (if desired)

When you restart your system, pywal will no longer work and your terminal will revert to the old color scheme.

If you want to keep the wallpaper-based color scheme, pywal provides a handy option -R which restores the last used color scheme.

All you have to do is add wal -R command to list your startup programs.

This step may be different for different distributions. On Ubuntu, you can manage startup applications using the “Startup Applications” program.

Add the command, give it a name and description like this:

Autostart Pywal

Now Pywal runs automatically on every reboot and restores the last used color scheme. In other words, your terminal will have colors based on your desktop background (if configured by pywal).

Take customization to the next level by adding the color scheme to other utilities

In many Linux communities, people share screenshots of their desktops. It’s the FOSS Facebook group that hosts the DesktopFriday posts where members share their desktops and you’ll also find them using Pywal for other apps.

Pywal has some plugins that extend the color scheme to Vim, Emacs, Gnuplot or even CLI-Visualizer (audio visualizer).

Pywal
Credit: cli-visualizer

You can also use Pywal with window managers like i3, sway and taskbars like polybar. Lots of customization possibilities if you are interested.

Do you like Pywal?

I understand that not everyone wants to change the look of their desktop, but for those who do, Pywal is an awesome utility.

And you? Did you like Pywal ? Do you know of another such utility that you would like to see covered in our “Terminal Tuesday” series? I welcome your comments and suggestions.

Share.

Comments are closed.