Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Live Coding a Shell Script to Toggle Dark Mode for Terminal Tools

live-coding-a-shell-script-to-toggle-dark-mode-for-terminal-tools.jpg

In this video, we'll update the config files of a few tools using a combination of shell scripting, grep and perl.

Quick Jump:

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

Do you prefer dark or light themes for coding? Let me know below.

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments