Add setting of fish theme and add wombat theme

This commit is contained in:
ViViDboarder 2021-09-01 15:04:56 -07:00
parent a75ef60330
commit 87c1191113
3 changed files with 142 additions and 54 deletions

View File

@ -6,13 +6,13 @@ import os
import sys import sys
import textwrap import textwrap
from subprocess import PIPE, Popen, check_output from subprocess import PIPE, Popen, check_output
from typing import Tuple from typing import Optional, Tuple
TERM_VAR = "TERM_PROFILE" TERM_VAR = "TERM_PROFILE"
VIM_VAR = "VIM_COLOR" VIM_VAR = "VIM_COLOR"
NVIM_VAR = "NVIM_COLOR" NVIM_VAR = "NVIM_COLOR"
BAT_VAR = "BAT_THEME" BAT_VAR = "BAT_THEME"
FISH_VAR = "FISH_THEME"
TERMINAL_SETTINGS_SCRIPT = """ TERMINAL_SETTINGS_SCRIPT = """
set current_tty to "{}" set current_tty to "{}"
tell application "Terminal" tell application "Terminal"
@ -158,6 +158,33 @@ def get_bat_theme(terminal_profile: str, force_dark=False, force=False) -> str:
return bat_theme return bat_theme
def get_fish_theme(
terminal_profile: str,
force_dark=False,
force=False,
) -> Optional[str]:
"""Returns the best matched fish theme for the terminal"""
if not force and FISH_VAR in os.environ:
return os.environ[FISH_VAR]
# Determine if this is a dark theme
is_dark = force_dark or "dark" in terminal_profile.lower()
fish_theme: Optional[str] = None
if "Wombat" in terminal_profile:
fish_theme = "wombat"
elif terminal_profile == "Alacritty":
fish_theme = "wombat"
elif "Solarized" in terminal_profile:
if is_dark:
fish_theme = "solarized dark"
else:
fish_theme = "solarized light"
return fish_theme
def parse_args(**args) -> argparse.Namespace: def parse_args(**args) -> argparse.Namespace:
"""Parse and return args from the terminal""" """Parse and return args from the terminal"""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
@ -205,6 +232,11 @@ def parse_args(**args) -> argparse.Namespace:
action="store_true", action="store_true",
help="Print only the value of the bat theme", help="Print only the value of the bat theme",
) )
group.add_argument(
"--print-fish",
action="store_true",
help="Print only the value of the fish theme",
)
parser.add_argument( parser.add_argument(
"--force", "--force",
action="store_true", action="store_true",
@ -250,6 +282,15 @@ def print_all_env(force=False, force_dark=False, export=False, fish=False):
bat_theme = get_bat_theme(term_profile, force_dark=force_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) print_env(BAT_VAR, bat_theme, export=export, fish=fish)
# Fish theme is optional, so don't print if None
fish_theme = get_fish_theme(
term_profile,
force_dark=force_dark,
force=force,
)
if fish_theme is not None:
print_env(FISH_VAR, fish_theme, export=export, fish=fish)
def print_env(var: str, val: str, export=False, fish=False): def print_env(var: str, val: str, export=False, fish=False):
"""Print variable in env format""" """Print variable in env format"""
@ -300,6 +341,14 @@ def main():
force=args.force, force=args.force,
) )
print(bat_theme) print(bat_theme)
elif args.print_fish:
term_profile = get_terminal_profile(force=args.force)
fish_theme = get_fish_theme(
term_profile,
force_dark=args.dark,
force=args.force,
)
print(fish_theme)
else: else:
print_all_env( print_all_env(
force=args.force, force=args.force,

View File

@ -2,56 +2,94 @@ function _set_colorscheme --description "Sets the fish colorscheme"
set -l theme "$argv[1]" set -l theme "$argv[1]"
switch "$theme" switch "$theme"
case "solarized light" case "solarized light"
set -g fish_color_autosuggestion 93a1a1 __theme_solarized_light
set -g fish_color_cancel -r
set -g fish_color_command 586e75
set -g fish_color_comment 93a1a1
set -g fish_color_cwd green
set -g fish_color_cwd_root red
set -g fish_color_end 268bd2
set -g fish_color_error dc322f
set -g fish_color_escape 00a6b2
set -g fish_color_history_current --bold
set -g fish_color_host normal
set -g fish_color_match --background=brblue
set -g fish_color_normal normal
set -g fish_color_operator 00a6b2
set -g fish_color_param 657b83
set -g fish_color_quote 839496
set -g fish_color_redirection 6c71c4
set -g fish_color_search_match bryellow --background=white
set -g fish_color_selection white --bold --background=brblack
set -g fish_color_user brgreen
set -g fish_color_valid_path --underline
set -g fish_pager_color_completion green
set -g fish_pager_color_description B3A06D
set -g fish_pager_color_prefix cyan --underline
set -g fish_pager_color_progress brwhite --background=cyan
case "solarized dark" case "solarized dark"
set -g fish_color_autosuggestion 586e75 __theme_solarized_dark
set -g fish_color_cancel -r case "wombat"
set -g fish_color_command 93a1a1 __theme_wombat
set -g fish_color_comment 586e75
set -g fish_color_cwd green
set -g fish_color_cwd_root red
set -g fish_color_end 268bd2
set -g fish_color_error dc322f
set -g fish_color_escape 00a6b2
set -g fish_color_history_current --bold
set -g fish_color_host normal
set -g fish_color_match --background=brblue
set -g fish_color_normal normal
set -g fish_color_operator 00a6b2
set -g fish_color_param 839496
set -g fish_color_quote 657b83
set -g fish_color_redirection 6c71c4
set -g fish_color_search_match bryellow --background=black
set -g fish_color_selection white --bold --background=brblack
set -g fish_color_user brgreen
set -g fish_color_valid_path --underline
set -g fish_pager_color_completion B3A06D
set -g fish_pager_color_description B3A06D
set -g fish_pager_color_prefix cyan --underline
set -g fish_pager_color_progress brwhite --background=cyan
end end
end end
function __theme_solarized_light --description "Set fish theme to solarized light"
set -g fish_color_autosuggestion 93a1a1
set -g fish_color_cancel -r
set -g fish_color_command 586e75
set -g fish_color_comment 93a1a1
set -g fish_color_cwd green
set -g fish_color_cwd_root red
set -g fish_color_end 268bd2
set -g fish_color_error dc322f
set -g fish_color_escape 00a6b2
set -g fish_color_history_current --bold
set -g fish_color_host normal
set -g fish_color_match --background=brblue
set -g fish_color_normal normal
set -g fish_color_operator 00a6b2
set -g fish_color_param 657b83
set -g fish_color_quote 839496
set -g fish_color_redirection 6c71c4
set -g fish_color_search_match bryellow --background=white
set -g fish_color_selection white --bold --background=brblack
set -g fish_color_user brgreen
set -g fish_color_valid_path --underline
set -g fish_pager_color_completion green
set -g fish_pager_color_description B3A06D
set -g fish_pager_color_prefix cyan --underline
set -g fish_pager_color_progress brwhite --background=cyan
end
function __theme_solarized_dark --description "Set fish theme to solarized dark"
set -g fish_color_autosuggestion 586e75
set -g fish_color_cancel -r
set -g fish_color_command 93a1a1
set -g fish_color_comment 586e75
set -g fish_color_cwd green
set -g fish_color_cwd_root red
set -g fish_color_end 268bd2
set -g fish_color_error dc322f
set -g fish_color_escape 00a6b2
set -g fish_color_history_current --bold
set -g fish_color_host normal
set -g fish_color_match --background=brblue
set -g fish_color_normal normal
set -g fish_color_operator 00a6b2
set -g fish_color_param 839496
set -g fish_color_quote 657b83
set -g fish_color_redirection 6c71c4
set -g fish_color_search_match bryellow --background=black
set -g fish_color_selection white --bold --background=brblack
set -g fish_color_user brgreen
set -g fish_color_valid_path --underline
set -g fish_pager_color_completion B3A06D
set -g fish_pager_color_description B3A06D
set -g fish_pager_color_prefix cyan --underline
set -g fish_pager_color_progress brwhite --background=cyan
end
function __theme_wombat --description "Set fish theme to wombat"
set -g fish_color_autosuggestion black
set -g fish_color_cancel -r
set -g fish_color_command yellow
set -g fish_color_comment normal
set -g fish_color_cwd green
set -g fish_color_cwd_root red
set -g fish_color_end blue
set -g fish_color_error red
set -g fish_color_escape magenta
set -g fish_color_history_current --bold
set -g fish_color_host normal
set -g fish_color_match --background=brblue
set -g fish_color_normal normal
set -g fish_color_operator cyan
set -g fish_color_param green
set -g fish_color_quote brgreen --italics
set -g fish_color_redirection magenta
set -g fish_color_search_match bryellow --background=green
set -g fish_color_selection white --bold --background=green
set -g fish_color_user brgreen
set -g fish_color_valid_path --underline
set -g fish_pager_color_completion blue
set -g fish_pager_color_description blue
set -g fish_pager_color_prefix cyan --underline
set -g fish_pager_color_progress brwhite --background=cyan
end

View File

@ -30,7 +30,8 @@ if status --is-interactive
# Export colors # Export colors
eval ($HOME/bin/derive_colors.py --export --fish) eval ($HOME/bin/derive_colors.py --export --fish)
if [ "$VIM_COLOR" = "solarized" ] # Set fish theme based on newly exported colors
_set_colorscheme "solarized light" if set -q FISH_THEME
_set_colorscheme "$FISH_THEME"
end end
end end