A Terminal, tmux, Vim and FZF Theme Switching Script written in Python
We'll go over a zero dependency Python 3 script to quickly change themes and toggle dark / light mode for various command line tools.
After 2 years of using Gruvbox and 1 year of using One I decided it was time to switch back to using Gruvbox for now. I realized it was kind of a pain to update a bunch of color values in a few config files so I spent a few hours whipping up a script to switch themes.
Back in mid-2020 I created a toggle-dark-mode script but it only supported one theme. This new set-theme script is a successor to this script.
In this video we’ll go over how it works, how to customize it for other themes and also go over a bit of the Python code along the way.
# Going Over the Script
Timestamps
- 0:07 – Quickly change your theme with this script
- 0:58 – I’m going back to Gruvbox and it was tedious to change everything manually
- 1:58 – Installing this set-theme script with or without my dotfiles
- 3:11 – Adding a custom theme to the script
- 8:36 – Modifying the script to use a different terminal instead of the Microsoft Terminal
- 11:42 – Adding the Gruvbox theme to the Microsoft Terminal
- 12:40 – Why there’s a 1 second sleep in the set-theme script
- 15:17 – Did you add a custom theme? Please open a pull request
Commands Run
set-theme gruvbox
set-theme gruvbox --toggle-bg
set-theme one
set-theme one --toggle-bg
Important Updates
There’s been at least 1 update to the script since I recorded this video.
January 25th 2021
The set-theme script was updated to avoid needing the 1 second sleep. This ended up being a pretty big refactor of the script thanks to an amazing pull request from someone who watched the above video.
The instructions mentioned at 11:42 in the video no longer match the script if you want to use a different terminal.
The documentation has been updated to reflect the new changes. I’m sure you’ll have no problem applying it based on this video + the updated docs.
Reference Links
- https://nickjanetakis.com/blog/live-coding-a-shell-script-to-toggle-dark-mode-for-terminal-tools
- The
set-script
is on GitHub in my dotfiles - https://nickjanetakis.com/blog/using-python-and-youtubes-api-to-get-comments-from-a-youtube-video
- https://nickjanetakis.com/blog/3-practical-examples-of-using-bash-while-and-until-loops
Are you going to use this script to manage your terminal themes? Let us know below.