aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-10-29 23:37:46 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-10-29 23:37:46 +1300
commitf47a6aab7726cec5700ad0cd23e53b26ba14dd2f (patch)
treeb42e825dae224b0774a3239c0c049c0d1b6f355d
parentAdd explanatory comment for Vim 'nocompatible' (diff)
parentSwitch on COLORFGBG to get background lightness (diff)
downloaddotfiles-f47a6aab7726cec5700ad0cd23e53b26ba14dd2f.tar.gz
dotfiles-f47a6aab7726cec5700ad0cd23e53b26ba14dd2f.zip
Merge branch 'vim/guess-background'
-rw-r--r--tmux/tmux.conf4
-rw-r--r--vim/config/syntax.vim29
-rw-r--r--vim/vimrc4
3 files changed, 30 insertions, 7 deletions
diff --git a/tmux/tmux.conf b/tmux/tmux.conf
index 4e277515..2eb1665a 100644
--- a/tmux/tmux.conf
+++ b/tmux/tmux.conf
@@ -1,7 +1,5 @@
# Strip out a lot of machine and X11 dependent crap from the initial
# environment
-set-environment -gru COLORFGBG
-set-environment -gru COLORTERM
set-environment -gru DISPLAY
set-environment -gru SSH_CLIENT
set-environment -gru SSH_CONNECTION
@@ -10,7 +8,7 @@ set-environment -gru WINDOWID
# Otherwise, use the environment we had when we started; don't touch it during
# a session unless I specifically ask
-set-option -g update-environment ''
+set-option -g update-environment 'COLORFGBG COLORTERM'
# Setting this makes each new pane a non-login shell, which suits me better
set-option -g default-command "$SHELL"
diff --git a/vim/config/syntax.vim b/vim/config/syntax.vim
index af332ba3..250ce924 100644
--- a/vim/config/syntax.vim
+++ b/vim/config/syntax.vim
@@ -5,8 +5,31 @@ if has('syntax')
silent! syntax enable
silent! syntax sync minlines=100
- " I almost always use a dark background, so use that version of the selected
- " colorscheme
- set background=dark
+ " Invert Vim's built-in logic for choosing dark or light backgrounds; we'll
+ " default to choosing a dark background unless we find some reason *not* to.
+ if has('eval')
+
+ " Wrap all this logic in a function
+ function! DetectBackground()
+
+ " Split up the value of $COLORFGBG (if any) by semicolons
+ let l:colorfgbg = split($COLORFGBG, ';')
+
+ " Get the background color value, or an empty string if none
+ let l:bg = len(l:colorfgbg) ? l:colorfgbg[-1] : ''
+
+ " Choose the background setting based on this value
+ if l:bg == 'default' || l:bg == '7' || l:bg == '15'
+ set background=light
+ else
+ set background=dark
+ endif
+
+ endfunction
+
+ " Cull the function just defined directly
+ call DetectBackground()
+
+ endif
endif
diff --git a/vim/vimrc b/vim/vimrc
index d225a148..043dea8b 100644
--- a/vim/vimrc
+++ b/vim/vimrc
@@ -24,8 +24,10 @@ if v:version >= 701
silent! call pathogen#infect()
silent! call pathogen#helptags()
- " With the plugins loaded, we might now be able to use my custom colorscheme
+ " The 'sahara' colorscheme only works for dark backgrounds with 256 colors
if has('syntax')
+ \ && &background == 'dark'
+ \ && (has('gui_running') || &t_Co == 256)
silent! colorscheme sahara
endif
endif