Skip to content

Instantly share code, notes, and snippets.

@romac
Last active June 19, 2020 10:20
Show Gist options
  • Save romac/eedd5b00ddd3e32ad328b56a623f133b to your computer and use it in GitHub Desktop.
Save romac/eedd5b00ddd3e32ad328b56a623f133b to your computer and use it in GitHub Desktop.
Switch between iTerm profiles based on the active macOS theme

Usage

  1. Install https://github.com/sindresorhus/dark-mode

    $ brew install dark-mode
  2. Download iterm_profile.zsh

    $ git clone https://gist.github.com/romac/6538f76874d276beab3f260a0aa34fcf $HOME/some/directory/iterm_profile
  3. Source iterm_profile.zsh

    $ echo 'source $HOME/some/directory/iterm_profile/iterm_profile.zsh' >> .zshrc
  4. Open a new shell, et voila!

    Note: You can manually trigger a profile change with:

    $ adapt_theme

Integration with (Neo)Vim

You can choose a Vim theme based on the current iTerm Profile with:

if $ITERM_PROFILE == 'Light'
  set background=light
  colorscheme solarized8_high
else
  set background=dark
  colorscheme hybrid
endif
if [[ -z $ITERM_PROFILE ]]; then
return 1
fi
function iterm_profile {
if [[ -z $1 ]]; then
profile="Default"
else
profile="$1"
fi
echo -e "\033]50;SetProfile=$profile\a"
}
function adapt_theme {
dark_mode="$(dark-mode status)"
if [ "$dark_mode" = "on" ]; then
profile="Dark"
else
profile="Light"
fi
iterm_profile "$profile"
ITERM_PROFILE="$profile"
}
adapt_theme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment