Matching colors of terminal with wallpaper

Yesterday I switch to endeavour from arch. As I like i3wm I’m using it here too. I made some changes to config in the same way I’ve done it in arch. I changed wallpaper using feh and tried changing terminal colors using pywal.

exec --no-startup-id sleep 1 && feh --bg-fill ~/Wallpapers/(wallpaper)
exec_always wal -i  ~/Wallpapers/(wallpaper)

The odd thing is that this works only after I open terminal and restart i3 config.
I am using kitty as terminal and fish as shell.
Can someone tell me if there is some other way required in endeavour to do this?

I am not sure if this is the only way but this is how I use it:

In i3config I have

exec_always --no-startup-id wal -R -o $HOME/.config/wal/wal_cleanup.sh

That wal_cleanup.sh is just deleting feh file because I hate useless clutter in my home directory.

#!/bin/bash

# remove useless feh file
rm "$HOME/.fehbg"

The -R flag tells wal to restore previous color theme from cache on every i3wm restart. The -i flag tries to generate a new scheme which takes some time and it may not be directly applied to an open windows.

When I want to change the color theme I use a different commad that is bound to a key combination.

#inside i3config
bindsym $mod+Shift+Ctrl+t exec --no-startup-id "~/.config/wal/wal_theme.sh"

It randomly selects a picture from a directory and then calls wal on it.

#inside wal_theme.sh
wal -e --backend wal -i "${WALLPAPER}" -o "${HOME}/.config/wal/wal_cleanup.sh"
i3-msg restart

The important part here is that it also restarts i3wm. That combined with wal -R on every i3wm restart (see above) will change colors on all active terminals.

This sadly did not work.

I suspect you need a way to guarantee that pywal is executed after feh has completed its execution.

You can either do this with i3’s command chaining or with the && operator.

# Option 1: Command chaining
exec --no-startup-id feh --bg-fill ~/Wallpapers/(wallpaper) ; wal -i ~/Wallpapers/(wallpaper)

# Option 2: &&
exec --no-startup-id feh --bg-fill ~/Wallpapers/(wallpaper) && wal -i ~/Wallpapers/(wallpaper)

After I did that it stopped working at all.

When you use wal you do not have to set wallpaper with feh - that is redundant.

Which part?
Can you run those command from a terminal and post what it outputs?

wal -i /path/to/your/wallpaper

then

i3-msg restart

and also

wal -R

Also I noticed I was missing " in my example above - fixing it now

What display manager is in use? Some display managers can set a wallpaper. I am wondering if the display manager is setting a background after the i3 config has already been loaded. Check your display manager’s config file to see if it calls for a wallpaper.


That is what I get after running those commands, and it does change colors of terminal but only for one that I run commands in.

It does not look like lightdm is setting any wallpapers, but I do not know much about display managers.

Ok, then it looks like that may be something terminal related.
I use allacrity which reloads colors from its config file every time there is a change and wal modifies this config → therefore it works for me.

For you, as you mentioned, you use Kitty terminal.
This link mentiones something about theming for the terminal.

Basicaly you can create your own theme

~/.config/kitty/kitty_wal_theme.conf

and switch to that theme kitty_wal_theme in Kitty terminal.
I have no idea what should be in that file but perhaps there is a template file somewhere in the .config directory.

From that you can create a template file for wal like
~/.config/wal/templates/kitty_wal_theme.conf

The template has to substitute colors with {colorX} flag.

For example if the final kitty theme file should look like this

click here for kitty config file
  primary:
    background: '#161e16'
    foreground: '#dce3e5'

  # Normal colors
  normal:
    black:   '#161e16'
    red:     '#8EB890'
    green:   '#9DBEA3'
    yellow:  '#9EC1A3'
    blue:    '#A2C1A4'
    magenta: '#B2D3DA'
    cyan:    '#B6D5E1'
    white:   '#dce3e5'

  # Bright colors
  bright:
    black:   '#9a9ea0'
    red:     '#8EB890'
    green:   '#9DBEA3'
    yellow:  '#9EC1A3'
    blue:    '#A2C1A4'
    magenta: '#B2D3DA'
    cyan:    '#B6D5E1'
    white:   '#dce3e5'

The template should look like this

click here for wal template file
  primary:
    background: '{background}'
    foreground: '{foreground}'

  # Normal colors
  normal:
    black:   '{color0}'
    red:     '{color1}'
    green:   '{color2}'
    yellow:  '{color3}'
    blue:    '{color4}'
    magenta: '{color5}'
    cyan:    '{color6}'
    white:   '{color7}'

  # Bright colors
  bright:
    black:   '{color8}'
    red:     '{color9}'
    green:   '{color10}'
    yellow:  '{color11}'
    blue:    '{color12}'
    magenta: '{color13}'
    cyan:    '{color14}'
    white:   '{color15}'

wal will generate the file somewhere in .cache every time you run wal -i command.
You just have to copy it to the kitty config directory and switch to that theme.
It is best to use a little script for that.

A script ~/.config/wal/wal_theme.sh (do not forget to set chmod +x flag on it so it can execute)

#!/bin/bash

case "$1" in
--set_new)
    # update theme with new wallpaper
    wal -i "$2"
    # copy kitty theme
    cp -f ~/.cache/wal/kitty_wal_theme.conf ~/.config/kitty/kitty_wal_theme.conf
    # set new theme in kitty
    kitty +kitten themes --reload-in=all kitty_wal_theme
    ;;

--reload)
    # reload theme from cache
    wal -R
    # copy kitty theme
    cp -f ~/.cache/wal/kitty_wal_theme.conf ~/.config/kitty/kitty_wal_theme.conf
    # set new theme in kitty
    kitty +kitten themes --reload-in=all kitty_wal_theme
    ;;
esac

You should be able to test this script from the terminal.

~/.config/wal/wal_theme.sh` --set_new "path/to/your/wallpaper"

And in your i3wm config you can have this line to reload theme on every i3wm restart.

exec_always --no-startup-id "~/.config/wal/wal_theme.sh --reload"

Please note that I did not thest these scripts so I do not know if they are correct.


One more option is to load colors in bash

## theme options
shopt -q login_shell
if [[ $? != 0 ]]; then
    [[ -f "${HOME}/.cache/wal/sequences" ]] && cat "${HOME}/.cache/wal/sequences"
fi
[[ -f "${HOME}/.cache/wal/colors-tty.sh" ]] && source "${HOME}/.cache/wal/colors-tty.sh"

I used to use this approach some time ago but I have no idea what will id do to your termianls.
It also sets the color theme for tty but I found it somewhat problematic because when I have to do something in tty it means i3wm is broken and most likely theme may be broken as well → tty becomes problematic to use.

And again script works when I run it from terminal, but commands in config does not work it is like i3 does not execute whole config and terminal always opens with default colors. I checked other terminals, and it does not work in them either (I know that script would not work I checked other methods).

In that case I am not sure how to solve it. I do not have Kitty terminal and this kind of approach works for me when I use Alacritty.

If kitty +kitten themes --reload-in=all some_theme does not change other than active terminal window then maybe it cannot be done.

I will probably go back to alacritty too. Maybe it will work there, if not then I will live with it till next time i switch back to arch.

Only way that I found to change theme for good is to create your own https://github.com/kovidgoyal/kitty-themes there is a template how to make your own theme and you place it in .config/kitty/theme and load it according to guide on this github. Colors of your wallpaper that pywal extracts are in ~/.cache/wal

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.