mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-11-17 21:26:27 +00:00
Add auto switching vim colors based on macOS theme
This commit is contained in:
parent
b79938f0be
commit
4e437e9f59
@ -75,10 +75,6 @@ set notitle
|
|||||||
|
|
||||||
" Function and command to update colors based on light and dark mode
|
" Function and command to update colors based on light and dark mode
|
||||||
function! UpdateColors()
|
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
|
" Get the light color or default to VIM_COLOR
|
||||||
let light_color = $VIM_COLOR
|
let light_color = $VIM_COLOR
|
||||||
if !empty($VIM_COLOR_LIGHT)
|
if !empty($VIM_COLOR_LIGHT)
|
||||||
@ -89,13 +85,17 @@ function! UpdateColors()
|
|||||||
if !empty($VIM_COLOR_DARK)
|
if !empty($VIM_COLOR_DARK)
|
||||||
let dark_color = $VIM_COLOR_DARK
|
let dark_color = $VIM_COLOR_DARK
|
||||||
endif
|
endif
|
||||||
" Find out if macOS is in dark mode
|
" Detect using an env variable
|
||||||
let cmd = "osascript
|
let cmd = "echo $IS_DARKMODE"
|
||||||
\ -e 'tell application \"System Events\"'
|
" On macOS we can do something a bit more fancy
|
||||||
\ -e 'tell appearance preferences'
|
if IsMac()
|
||||||
\ -e 'return dark mode'
|
let cmd = "osascript
|
||||||
\ -e 'end tell'
|
\ -e 'tell application \"System Events\"'
|
||||||
\ -e 'end tell'"
|
\ -e 'tell appearance preferences'
|
||||||
|
\ -e 'return dark mode'
|
||||||
|
\ -e 'end tell'
|
||||||
|
\ -e 'end tell'"
|
||||||
|
endif
|
||||||
let dark_mode = substitute(system(cmd), '\n', '', 'g')
|
let dark_mode = substitute(system(cmd), '\n', '', 'g')
|
||||||
" Set colorscheme and background based on mode
|
" Set colorscheme and background based on mode
|
||||||
if dark_mode == 'true'
|
if dark_mode == 'true'
|
||||||
@ -107,4 +107,5 @@ function! UpdateColors()
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
command! UpdateColors call UpdateColors()
|
command! UpdateColors call UpdateColors()
|
||||||
|
" au BufEnter *.* call UpdateColors()
|
||||||
call UpdateColors()
|
call UpdateColors()
|
||||||
|
Loading…
Reference in New Issue
Block a user