Are you someone who finds themselves using a terminal for coding and execution more than an IDE?
Are you using OSX and iTerm?
Do you find yourself coding in dark and light environments?
Are you concerned that Dark mode themes are not that great for your eyesight, but still crave something softer late at night or in the early hours of the morning?
Then you're in the same position as me. I was frustrated by the lack of support for the OS dark mode preference. To make my life better, I went out of my way to build scripts to bridge the gap.

iTerm2 in Light Mode

iTerm2 in Dark Mode

Setup iTerm2 profiles "dark" and "light" through Preferences > Profiles. Use the little plus on

Setup OSX to automatically switch between light and dark mode through Settings > Appearance > "Auto"
Download and install iTerm2 themes for Rosé Pine Dawn (light) and Rosé Pine Moon (dark). Github
Setup iterm2 profiles named "dark" and "light" to match intention. We'll use profiles should use themes you installed from Rosé Pine for consistency.
Append the following code to ~/.zshrc to set dark or light mode when zsh loads.
# Credit: https://coderwall.com/p/s-2_nw/change-iterm2-color-profile-from-the-cli terminal_profile() { echo -e "\033]1337;SetProfile=$1\a" } # Set iterm colours # n.b. LC_APPEARANCE is a hack. SSH accepts LC_* by default so hosts can be dark mode aware # n.b. iterm themes MUST be lowercase 'light' and 'dark' for reuse in vimrc's background setup # see https://iterm2.com/documentation-escape-codes.html alias dark='export LC_APPEARANCE=dark && terminal_profile dark' alias light='export LC_APPEARANCE=light && terminal_profile light' if [ -z "$SSH_CLIENT" ]; then # Detect OSX dark mode appearance=$(defaults read -g AppleInterfaceStyle 2> /dev/null || echo "Light") if [ $appearance = 'Dark' ]; then # Dark mode isn't as good for your eyes as you believe # https://www.wired.co.uk/article/dark-mode-chrome-android-ios-science dark else light fi fi
If you're a Vim user, you can hook into the exported environment variable LC_APPEARANCE by appending this to your ~/.vimrc
if !empty($LC_APPEARANCE) exec 'set background=' . $LC_APPEARANCE endif
You might be wondering why this is LC_APPEARANCE and why there is a guard in ~/.zshrc for running over ssh. Well if you're copying your dotfiles to all the hosts that you manage, then this OSX dark mode behaviour is unlikely to be on those remote hosts. This technique uses escape sequences to communicate with iTerm2, and those sequences also work over SSH
i.e. \033]1337;SetProfile=$1\a
However, the problem is your vim configuration now doesn't know how to set backgrond=dark at night. Well that's where LC_APPERANCE comes in.
You can forward LC_APPERANCE to remote hosts by adding this to your ~/.ssh/config
Host * SendEnv LC_APPEARANCE # remotes in dark mode
I made up LC_APPERANCE to follow allowed forwards in SSH. You can see this rule if you open /etc/ssh/ssh_config. It's a * rule that exists to forward your language preferences so it'll be present on most of your hosts.
# Allow client to pass locale environment variables AcceptEnv LANG LC_*