Dynamically detect session theme and set vim theme

This commit is contained in:
ViViDboarder 2017-10-31 18:42:24 -07:00
parent 3b93b32dfe
commit ba2afb7df0
3 changed files with 57 additions and 2 deletions

View File

@ -0,0 +1,55 @@
#! /bin/bash
# Gets the current settings for the given terminal window
function get_terminal_settings {
case "$TERM_PROGRAM" in
Apple_Terminal)
osascript <<EOD
set current_tty to "$(tty)"
tell application "Terminal"
repeat with win in windows
repeat with the_tab in tabs of win
set tab_settings to the current settings of the_tab
if current_tty is equal to the tty of the_tab then
return the name of tab_settings
end if
end repeat
end repeat
end tell
EOD
;;
iTerm.app)
echo "$ITERM_PROFILE"
;;
*)
echo "Unknown terminal $TERM_PROGRAM"
exit 1
esac
}
# Mappings of Terminal themes to color schemes
function get_vim_colorscheme {
local term_theme="$1"
case "$term_theme" in
"Hotkey Window Wombat")
echo "wombat256mod"
;;
Wombat*)
echo "wombat256mod"
;;
Solarized*)
echo "solarized"
;;
"Yosemite Light"*)
echo "morning"
;;
"Yosemite Dark"*)
echo "vividchalk"
;;
*)
echo "default"
;;
esac
}
get_vim_colorscheme "$(get_terminal_settings)"

View File

@ -70,7 +70,7 @@ export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Vim colors
[ -z "$VIM_COLOR" ] && export VIM_COLOR='wombat256mod'
[ -n "$VIM_COLOR" ] || export VIM_COLOR=$(eval $HOME/bin/get_vim_colorscheme.sh) || export VIM_COLOR='wombat256mod'
# Set file as having been loaded to avoid looping
#IS_BASH_PROFILE_LOADED=true

View File

@ -6,4 +6,4 @@ set -gx FZF_DEFAULT_COMMAND 'ag -g ""'
set -gx FZF_CTRL_T_COMMAND "$FZF_DEFAULT_COMMAND \$dir"
# Vim Colors so that they can be set by env
set -q VIM_COLOR; or set -gx VIM_COLOR wombat256mod
set -q VIM_COLOR; set -gx VIM_COLOR (eval $HOME/bin/get_vim_colorscheme.sh); or set -gx VIM_COLOR wombat256mod