Add auto switching vim colors based on macOS theme

This commit is contained in:
ViViDboarder 2019-10-16 09:24:17 -07:00
parent b79938f0be
commit 4e437e9f59

View File

@ -75,10 +75,6 @@ set notitle
" Function and command to update colors based on light and dark mode
function! UpdateColors()
"If not a mac, let's get out of here
if !IsMac()
return
endif
" Get the light color or default to VIM_COLOR
let light_color = $VIM_COLOR
if !empty($VIM_COLOR_LIGHT)
@ -89,13 +85,17 @@ function! UpdateColors()
if !empty($VIM_COLOR_DARK)
let dark_color = $VIM_COLOR_DARK
endif
" Find out if macOS is in dark mode
let cmd = "osascript
\ -e 'tell application \"System Events\"'
\ -e 'tell appearance preferences'
\ -e 'return dark mode'
\ -e 'end tell'
\ -e 'end tell'"
" Detect using an env variable
let cmd = "echo $IS_DARKMODE"
" On macOS we can do something a bit more fancy
if IsMac()
let cmd = "osascript
\ -e 'tell application \"System Events\"'
\ -e 'tell appearance preferences'
\ -e 'return dark mode'
\ -e 'end tell'
\ -e 'end tell'"
endif
let dark_mode = substitute(system(cmd), '\n', '', 'g')
" Set colorscheme and background based on mode
if dark_mode == 'true'
@ -107,4 +107,5 @@ function! UpdateColors()
endif
endfunction
command! UpdateColors call UpdateColors()
" au BufEnter *.* call UpdateColors()
call UpdateColors()