Use new color detection in bash/zsh/fish

This commit is contained in:
ViViDboarder 2020-10-06 13:17:45 -07:00
parent 6703812918
commit 25f73bef63
4 changed files with 17 additions and 14 deletions

View File

@ -59,7 +59,7 @@ def get_terminal_profile(force=False):
raise ValueError(f"Unknown terminal {term_program}")
def get_vim_colorscheme(terminal_profile: str, is_dark=False, force=False):
def get_vim_colorscheme(terminal_profile: str, force_dark=False, force=False):
"""Returns the best colorscheme for a given terminal profile"""
if not force and VIM_VAR in os.environ:
return os.environ[VIM_VAR]
@ -77,10 +77,13 @@ def get_vim_colorscheme(terminal_profile: str, is_dark=False, force=False):
return "wombat256mod"
def get_bat_theme(terminal_profile: str, is_dark=False, force=False):
def get_bat_theme(terminal_profile: str, force_dark=False, force=False):
if not force and BAT_VAR in os.environ:
return os.environ[BAT_VAR]
# Determine if this is a dark theme
is_dark = force_dark or "dark" in terminal_profile.lower()
if "Wombat" in terminal_profile:
return "DarkNeon"
elif "Solarized" in terminal_profile:
@ -165,18 +168,18 @@ def parse_args(**args) -> argparse.Namespace:
return parser.parse_args(**args)
def print_all_env(force=False, is_dark=False, export=False, fish=False):
def print_all_env(force=False, force_dark=False, export=False, fish=False):
term_profile = get_terminal_profile(force=force)
print_env(TERM_VAR, term_profile, export=export, fish=fish)
vim_colors = get_vim_colorscheme(
term_profile,
is_dark=is_dark,
force_dark=force_dark,
force=force,
)
print_env(VIM_VAR, vim_colors, export=export, fish=fish)
bat_theme = get_bat_theme(term_profile, is_dark=is_dark, force=force)
bat_theme = get_bat_theme(term_profile, force_dark=force_dark, force=force)
print_env(BAT_VAR, bat_theme, export=export, fish=fish)
@ -202,7 +205,7 @@ if __name__ == "__main__":
term_profile = get_terminal_profile(force=args.force)
vim_colors = get_vim_colorscheme(
term_profile,
is_dark=args.dark,
force_dark=args.dark,
force=args.force,
)
print(vim_colors)
@ -210,14 +213,14 @@ if __name__ == "__main__":
term_profile = get_terminal_profile(force=args.force)
bat_theme = get_bat_theme(
term_profile,
is_dark=args.dark,
force_dark=args.dark,
force=args.force,
)
print(bat_theme)
else:
print_all_env(
force=args.force,
is_dark=args.dark,
force_dark=args.dark,
fish=args.fish,
export=args.export,
)

View File

@ -80,8 +80,8 @@ export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Vim colors
[ -n "$VIM_COLOR" ] || export VIM_COLOR="$(eval "$HOME/bin/get_vim_colorscheme.sh")" || export VIM_COLOR='wombat256mod'
# Export colors
eval $($HOME/bin/derive_colors.py --export)
if type rg &> /dev/null; then
export FZF_DEFAULT_COMMAND='rg --files'

View File

@ -132,8 +132,8 @@ export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
# Vim colors
[ -n "$VIM_COLOR" ] || export VIM_COLOR="$(eval "$HOME/bin/get_vim_colorscheme.sh")" || export VIM_COLOR='wombat256mod'
# Export colors
eval $($HOME/bin/derive_colors.py --export)
# FZF
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

View File

@ -22,5 +22,5 @@ set -gx FZF_DEFAULT_OPTS "
--bind '?:toggle-preview'
"
# Vim Colors so that they can be set by env
set -q VIM_COLOR; set -gx VIM_COLOR (eval $HOME/bin/get_vim_colorscheme.sh); or set -gx VIM_COLOR wombat256mod
# Export colors
eval ($HOME/bin/derive_colors.py --export --fish)