ghostty: automatic switching between light/dark themes

This commit is contained in:
Daniel Lundin 2024-11-21 14:52:59 +01:00
parent 8ad810254b
commit 010e4bc4d7
Signed by: dln
SSH key fingerprint: SHA256:dQy1Xj3UiqJYpKR5ggQ2bxgz4jCH8IF+k3AB8o0kmdI

View file

@ -5,25 +5,11 @@
pkgs, pkgs,
... ...
}: }:
let
launch-ghostty = pkgs.writeShellApplication {
name = "launch-ghostty";
text = ''
if [ "$(gsettings get org.gnome.desktop.interface color-scheme)" = "'prefer-dark'" ]; then
theme="theme_dark"
else
theme="theme_light"
fi
exec ghostty --config-file="$HOME/.config/ghostty/$theme" "$@"
'';
};
in
{ {
config = lib.mkIf config.patagia.desktop.enable { config = lib.mkIf config.patagia.desktop.enable {
home.packages = with pkgs; [ home.packages = with pkgs; [
inputs.ghostty.packages.${pkgs.system}.default inputs.ghostty.packages.${pkgs.system}.default
launch-ghostty
]; ];
programs.ghostty = { programs.ghostty = {
@ -56,6 +42,7 @@ in
window-padding-balance = true; window-padding-balance = true;
window-padding-color = "extend"; window-padding-color = "extend";
window-theme = "system"; window-theme = "system";
theme = "light:PatagiaLight,dark:PatagiaDark";
keybind = [ keybind = [
"alt+shift+c=copy_to_clipboard" "alt+shift+c=copy_to_clipboard"
@ -76,7 +63,7 @@ in
}; };
}; };
xdg.configFile."ghostty/theme_dark".text = '' xdg.configFile."ghostty/themes/PatagiaDark".text = ''
background = #0d1117 background = #0d1117
foreground = #b2b2b2 foreground = #b2b2b2
cursor-color = #00d992 cursor-color = #00d992
@ -100,7 +87,7 @@ in
palette = 15=#ffffff palette = 15=#ffffff
''; '';
xdg.configFile."ghostty/theme_light".text = '' xdg.configFile."ghostty/themes/PatagiaLight".text = ''
background = #fefeff background = #fefeff
foreground = #222222 foreground = #222222
cursor-color = #aa0000 cursor-color = #aa0000
@ -130,13 +117,13 @@ in
"System" "System"
"TerminalEmulator" "TerminalEmulator"
]; ];
exec = ''launch-ghostty --class=com.mitchellh.ghostty-local -e "tmux new-session -A -s0 -nt1"''; exec = ''ghostty --class=com.mitchellh.ghostty-local -e "tmux new-session -A -s0 -nt1"'';
genericName = "Ghostty (local)"; genericName = "Ghostty (local)";
icon = "com.mitchellh.ghostty"; icon = "com.mitchellh.ghostty";
name = "Ghostty (local)"; name = "Ghostty (local)";
settings = { settings = {
StartupWMClass = "com.mitchellh.ghostty-local"; StartupWMClass = "com.mitchellh.ghostty-local";
TryExec = "launch-ghostty"; TryExec = "ghostty";
}; };
terminal = false; terminal = false;
type = "Application"; type = "Application";
@ -147,13 +134,13 @@ in
"System" "System"
"TerminalEmulator" "TerminalEmulator"
]; ];
exec = ''launch-ghostty --class=com.mitchellh.ghostty-nemo -e "ssh -t nemo tmux new-session -A -s0 -nt1"''; exec = ''ghostty --class=com.mitchellh.ghostty-nemo -e "ssh -t nemo tmux new-session -A -s0 -nt1"'';
genericName = "Ghostty (nemo)"; genericName = "Ghostty (nemo)";
icon = "com.mitchellh.ghostty"; icon = "com.mitchellh.ghostty";
name = "Ghostty (nemo)"; name = "Ghostty (nemo)";
settings = { settings = {
StartupWMClass = "com.mitchellh.ghostty-nemo"; StartupWMClass = "com.mitchellh.ghostty-nemo";
TryExec = "launch-ghostty"; TryExec = "ghostty";
}; };
terminal = false; terminal = false;
type = "Application"; type = "Application";