replace theme.sh with custom Terminal profile switcher
5 files changed, 55 insertions(+), 23 deletions(-)
A scripts/terminal/set-terminal-theme.applescript
@@ -0,0 +1,29 @@ +global lightProfile, darkProfile + +set lightProfile to "Flexoki Light" +set darkProfile to "Flexoki Dark" + +to getTargetProfile() + tell application "System Events" + set isDark to dark mode of appearance preferences + end tell + if isDark then + return darkProfile + else + return lightProfile + end if +end getTargetProfile + +to setTerminalProfile(targetProfile) + tell application "Terminal" + set default settings to settings set targetProfile + set startup settings to settings set targetProfile + + repeat with existingWindow in windows + set current settings of existingWindow to settings set targetProfile + end repeat + end tell +end setTerminalProfile + +getTargetProfile() +setTerminalProfile(result)
A scripts/terminal/toggle-light-dark
@@ -0,0 +1,11 @@ +#!/usr/bin/env fish + +set --function cmd osascript (status dirname)/set-terminal-theme.applescript + +set --function apple_interface_style (defaults read -g AppleInterfaceStyle 2> /dev/null) + +if test "$apple_interface_style" = Dark + $cmd $TERMINAL_THEME_DARK $argv +else + $cmd $TERMINAL_THEME_LIGHT $argv +end
M user/settings/darwin.nix → user/settings/darwin.nix
@@ -107,6 +107,18 @@ )) ]; }; }; + set-terminal-theme = { + enable = true; + config = { + WatchPaths = [ "${config.home.homeDirectory}/Library/Preferences/.GlobalPreferences.plist" ]; + RunAtLoad = true; + KeepAlive = false; + ProgramArguments = [ + "/usr/bin/osascript" + (builtins.toString ../../scripts/terminal/set-terminal-theme.applescript) + ]; + }; + }; }; home.shellAliases = {
D user/settings/fish/functions/toggle-light-dark.fish
@@ -1,7 +0,0 @@ -function toggle-light-dark - if test "$THEME_CURRENT" = "$THEME_LIGHT" - set_theme $THEME_DARK - else - set_theme $THEME_LIGHT - end -end
M user/settings/theme.nix → user/settings/theme.nix
@@ -54,10 +54,6 @@ }; }; }; - home.packages = with pkgs; [ - theme-sh - ]; - programs.nixvim.extraConfigVim = '' set notermguicolors '';@@ -88,22 +84,13 @@ home.sessionVariables = { CLICOLOR = "1"; LSCOLORS = "gxfxcxdxDxegedabagacad"; # for macOS's ls - THEME_LIGHT = "atelier-dune-light"; - THEME_DARK = "atelier-dune"; + TERMINAL_THEME_DARK = "Flexoki Dark"; + TERMINAL_THEME_LIGHT = "Flexoki Light"; }; programs.fish = { - shellAliases.theme = "theme.sh"; - - loginShellInit = '' - if test -e $XDG_CONFIG_HOME/.theme_history - theme.sh (theme.sh -l | tail -n1) - else - theme.sh $THEME_LIGHT - end - ''; interactiveShellInit = '' - bind ctrl-o toggle-light-dark + bind ctrl-o "sf terminal toggle-light-dark" ''; };