DEV Community

mafflerbach
mafflerbach

Posted on

Theme switcher based on rofi and pywal

I like to have a consistent color scheme across my wallpaper, terminal and other applications. Luckily my most frequent Programs are kitty, qutebrowser, rofi and i3wm. All of theme are able to be themed via configuration file.

  • kitty is my terminal emulator
  • rofi is a window switcher, Application launcher and dmenu replacement
  • qutebrowser is my main browser fully keyboard centric
  • and i3wm is my tilling window manager

If I'm in the mood to change my wallpaper (again) I'm using pywal. The installation is quite easy. Pywal is a tool that generates a color palette from the dominant colors from an image. It then applies the colors system-wide and on-the-fly in all of your favourite programs.

But the standard look of rofi which is generated by pywal is not satisfying me, so i have to generate my own rofi configuration. For this, i wrote this small script:


#!/bin/bash

# grab the purest color definition file
input="/home/maren/.cache/wal/colors"
i=0
content=""
while IFS= read -r line
do

    # generate the color list for my style config
    if [ $i -eq 0 ]; then 
        content="${content}  background:${line}00;"
        content="${content}  color$i:${line};"
    else 
        content="${content}  color$i:${line};"
    fi

    ((i++))

done < "$input"

# copied a template config to the actual config location
cp /home/maren/dotfiles/rofi/colors-rofi-template.rasi /home/maren/dotfiles/i3/rofi.rasi

# write in the 10th line my color list
sed -i "10i$content" /home/maren/dotfiles/i3/rofi.rasi

Enter fullscreen mode Exit fullscreen mode

For qutebrowser i am using qutewal

To switch between my wallpapers I have the following script.

#!/usr/bin/env bash

# feed rofi with the content of my wallpaper directory
wallpaper=`ls -1 /home/maren/Downloads/wallpapers | rofi -dmenu -theme ~/dotfiles/i3/rofi.rasi ` 

while getopts ld option
do
  case "${option}"
    in

    l) 
      # apply light theme
      wal -l -i /home/maren/Downloads/wallpapers/$wallpaper
    ;;
    d)
      # apply dark theme
      wal -i /home/maren/Downloads/wallpapers/$wallpaper
    ;;
esac
done

# change the rofi color theme 
/home/maren/dotfiles/scripts/rofiThemeGenerator.sh

Enter fullscreen mode Exit fullscreen mode

i3wm is highly configurable in case of keybindings and whit a
fast shortkey I can define my new theme with in seconds.

bindsym $mod+d exec "sh /home/maren/dotfiles/i3/script/themeswitcher.sh -d" 
bindsym $mod+l exec "sh /home/maren/dotfiles/i3/script/themeswitcher.sh -l" 
Enter fullscreen mode Exit fullscreen mode

Theme switcher

Top comments (0)