Last active
October 21, 2020 18:42
-
-
Save spazm/42f91818768f86b123de49f7a7ef5800 to your computer and use it in GitHub Desktop.
vimrc code for setting light/dark from environment variable and zsh aliases to set the ENV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" check ITERM_PROFILE for 'DARK' or 'LIGHT' substrings, set background to match. | |
if $ITERM_PROFILE =~? 'DARK\c' | |
set background=dark | |
endif | |
if $ITERM_PROFILE =~? 'LIGHT\c' | |
set background=light | |
endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias light='echo "setting ITERM_PROFILE to light"; export ITERM_PROFILE="light"' | |
alias dark='echo "setting ITERM_PROFILE to dark"; export ITERM_PROFILE="dark"' |
Edited .vimrc
- correctly do case-insensitive matching whether or not that is enabled as a default.
By adding a?
to the end of the comparator. - fix light check to check for substring match, rather than exact string (
=~
vs==
typo)
see the "LOGIC OPERATIONS" section 41.4 of the vim documentation: http://vimdoc.sourceforge.net/htmldoc/usr_41.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iterm2 exports an environment variable ITERM_PROFILE containing the (user defined) name of the profile.
Adding "Light" or "Dark" within the profile name will trigger automatic handling by the vim code above.
I don't even use iterm2 anymore, having gone back to a linux laptop. But none of the xterm derived terminals provide usable profile information. I find the light/dark commands a nice way to change if I'm stuck in a flipped terminal (like when giving presentations).