Live Coding a Shell Script to Toggle Dark Mode for Terminal Tools
In this video, we'll update the config files of a few tools using a combination of shell scripting, grep and perl.
This is just one example of using various command line tools to help solve a real world problem. I wanted a script to quickly toggle between dark and light mode for the terminal tools that I use and ~20 minutes later it was done.
Here’s the process from start to finish.
# Live Coding Session
Important code update
The version of the script included in this video has a bug where it would transform any files that were getting modified from a symlink into a real file.
An updated version of the script can be found here. It’s still worth watching the video since this is a minor change, although if you’re using MacOS make sure to read the comments at the top of the file.
Timestamps
- 0:18 – A personal note before we get started
- 1:15 – Switching between dark and light themes should be easy
- 3:05 – Creating a hello world script to get the ball rolling
- 5:12 – Thinking about how this script is going to work
- 6:55 – Figuring out if we’re in dark or light mode using grep
- 8:54 – Using Perl to do a cross OS inline replace on multiple files
- 11:47 – Refactoring hard coded config paths into variables
- 12:39 – Changing the Microsoft terminal theme settings from the script
- 16:51 – Switching around a few tmux colors programmatically
- 20:43 – Figuring out how to source your tmux config from the script
- 22:51 – Toggling FZF’s theme colors
- 27:59 – Accepting defeat on changing a parent’s ENV variable from a child process
- 34:44 – Reviewing the final script and doing a bit of refactoring
- 36:53 – What you’ll want to change to get this working on your end
Reference Links
- https://github.com/nickjj/dotfiles
- https://nickjanetakis.com/blog/transforming-an-idea-from-your-brain-into-an-open-source-project
- https://nickjanetakis.com/blog/organize-your-text-based-notes-from-the-command-line-with-this-script
- https://nickjanetakis.com/blog/using-unix-tools-and-bash-to-convert-blog-post-titles-part-1
- https://nickjanetakis.com/blog/find-and-replace-text-in-1-or-more-files-using-vim-fzf-and-ripgrep
- fzf color vimrc commit
- Toggle dark mode script commit
Do you prefer dark or light themes for coding? Let me know below.