1
0

Add functional theme changer to xonsh configuration

This commit is contained in:
Jip J. Dekker 2022-08-09 19:38:01 +10:00
parent a84f0dd035
commit aea2911de4
No known key found for this signature in database
GPG Key ID: 517DF4A00618C9C3

View File

@ -1,21 +1,7 @@
# --- Detect Environment ---
try:
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import darkdetect
dark_mode = darkdetect.isDark()
except ImportError:
dark_mode = False
import sys
brew_prefix = $(brew --prefix).strip()
# --- Xonsh Configuration ---
$XONSH_COLOR_STYLE = "stata-dark" if dark_mode else "stata-light"
# --- Path Variables ---
#> Use MacOS path_helper executable
source-bash $(/usr/libexec/path_helper -s)
@ -42,13 +28,53 @@ $CMAKE_GENERATOR = "Sublime Text 2 - Ninja" # use Ninja generator by default
$FZF_DEFAULT_COMMAND = "fd --type f"
# --- Aliases ---
def _theme(args):
"""This command takes a
"""
DARK_XONSH_STYLE = "stata-dark"
DARK_KITTY_STYLE = "Mariana"
LIGHT_XONSH_STYLE = "stata-light"
LIGHT_KITTY_STYLE = "Breakers"
if len(args) == 0 or args[0] == "info":
print("dark" if $XONSH_COLOR_STYLE == DARK_XONSH_STYLE else "light")
elif args[0] == "set":
dark_mode = False
if len(args) > 1:
if args[1] == "dark":
dark_mode = True
elif args[1] == "light":
dark_mode = False
else:
print(f"unknown theme `{args[1]}'", file=sys.stderr)
return 1
else:
try:
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
import darkdetect
dark_mode = darkdetect.isDark()
except ImportError:
print("darkdetect package not found (xpip install darkdetect)", file=sys.stderr)
$XONSH_COLOR_STYLE = DARK_XONSH_STYLE if dark_mode else LIGHT_XONSH_STYLE
$( kitty +kitten themes @(DARK_KITTY_STYLE if dark_mode else LIGHT_KITTY_STYLE) )
else:
print(f"unknown argument `{args[0]}'", file=sys.stderr)
return 1
return 0
aliases["brew-backup"] = ("brew", "bundle", "dump", "--global", "--no-lock", "--cask", "--mas", "--tap", "--force")
aliases["brew-cleanup"] = ("brew", "bundle", "cleanup", "--global", "--no-lock", "--force", "--zap")
aliases["brew-restore"] = ("brew", "bundle", "install", "--global", "--no-lock")
aliases["edit"] = $VISUAL
aliases["less"] = "bat"
aliases["ls"] = "exa"
aliases["set-dark-theme"] = ("kitty", "+kitten", "themes", "Mariana")
aliases["set-light-theme"] = ("kitty", "+kitten", "themes", "Breakers")
aliases["ssh"] = ("kitty", "+kitten", "ssh")
aliases["start"] = "open"
aliases["theme"] = _theme
# --- Set theme based on Dark Mode ---
_theme(["set"])