feat: dark mode sync module

This commit is contained in:
winston 2023-07-13 08:45:39 +02:00
parent b21b2be135
commit a2c5d32b97
Signed by: winston
GPG key ID: 3786770EDBC2B481
7 changed files with 102 additions and 27 deletions

View file

@ -0,0 +1,56 @@
{
config,
pkgs,
lib,
...
}: let
# TODO: de-duplicate across modules
lat = 48.210033;
lng = 16.363449;
in {
home.packages = [
(pkgs.writeShellApplication {
name = "dark-mode-ternary";
runtimeInputs = [pkgs.gnugrep];
text = let
queryCommand =
if pkgs.stdenv.isLinux
then "dbus-send --session --print-reply=literal --dest=org.freedesktop.portal.Desktop /org/freedesktop/portal/desktop org.freedesktop.portal.Settings.Read string:'org.freedesktop.appearance' string:'color-scheme' | grep -q 'uint32 1'"
else if pkgs.stdenv.isDarwin
then "defaults read -g AppleInterfaceStyle &>/dev/null"
else throw "Unsupported platform";
in ''
[[ -z "''${1-}" ]] && [[ -z "''${2-}" ]] && echo "Usage: $0 <dark> <light>" && exit 1
if ${queryCommand}; then
echo "$1"
else
echo "$2"
fi
'';
})
];
services.darkman = {
enable = true;
config = {
inherit lat lng;
useGeoclue = false;
};
activationScript = let
starship = lib.getExe config.programs.starship.package;
zsh = lib.getExe config.programs.zsh.package;
in {
dark = ''
${starship} config palette catppuccin_mocha
${zsh} -ic "fast-theme XDG:catppuccin-mocha"
'';
light = ''
${starship} config palette catppuccin_latte
${zsh} -ic "fast-theme XDG:catppuccin-latte"
'';
};
};
programs.zsh.shellAliases.cat = "bat --theme=$(dark-mode-ternary 'Catppuccin-mocha' 'Catppuccin-latte')";
}

View file

@ -1,6 +1,7 @@
{ {
imports = [ imports = [
./browsers.nix ./browsers.nix
./colorscheme-sync.nix
./discord.nix ./discord.nix
./fonts.nix ./fonts.nix
./git.nix ./git.nix

View file

@ -37,13 +37,6 @@ in {
services = lib.mkIf isLinux { services = lib.mkIf isLinux {
clipman.enable = true; clipman.enable = true;
darkman = {
enable = true;
config = {
inherit lat lng;
useGeoclue = false;
};
};
gnome-keyring = { gnome-keyring = {
enable = true; enable = true;
components = ["secrets"]; components = ["secrets"];

View file

@ -31,6 +31,21 @@ local openUrl = act.QuickSelectArgs({
end), end),
}) })
local changeCtpFlavor = act.InputSelector({
title = "Change Catppuccin flavor",
choices = {
{ label = "Mocha" },
{ label = "Macchiato" },
{ label = "Frappe" },
{ label = "Latte" },
},
action = wezterm.action_callback(function(window, _, _, label)
if label then
window:set_config_overrides({ color_scheme = "Catppuccin " .. label })
end
end),
})
-- use 'Backslash' to split horizontally -- use 'Backslash' to split horizontally
map("\\", "LEADER", act.SplitHorizontal({ domain = "CurrentPaneDomain" })) map("\\", "LEADER", act.SplitHorizontal({ domain = "CurrentPaneDomain" }))
-- and 'Minus' to split vertically -- and 'Minus' to split vertically
@ -53,6 +68,7 @@ map("l", "LEADER|SHIFT", act.AdjustPaneSize({ "Right", 5 }))
-- spawn & close -- spawn & close
map("c", "LEADER", act.SpawnTab("CurrentPaneDomain")) map("c", "LEADER", act.SpawnTab("CurrentPaneDomain"))
map("x", "LEADER", act.CloseCurrentPane({ confirm = true })) map("x", "LEADER", act.CloseCurrentPane({ confirm = true }))
map("t", "LEADER", changeCtpFlavor)
map("t", { "SHIFT|CTRL", "SUPER" }, act.SpawnTab("CurrentPaneDomain")) map("t", { "SHIFT|CTRL", "SUPER" }, act.SpawnTab("CurrentPaneDomain"))
map("w", { "SHIFT|CTRL", "SUPER" }, act.CloseCurrentTab({ confirm = true })) map("w", { "SHIFT|CTRL", "SUPER" }, act.CloseCurrentTab({ confirm = true }))
map("n", { "SHIFT|CTRL", "SUPER" }, act.SpawnWindow) map("n", { "SHIFT|CTRL", "SUPER" }, act.SpawnWindow)

View file

@ -1,12 +1,6 @@
---@type wezterm ---@type wezterm
local wezterm = require("wezterm") local wezterm = require("wezterm")
local utils = require("utils") local c = wezterm.config_builder()
local c = {}
if wezterm.config_builder then
c = wezterm.config_builder()
c:set_strict_mode(true)
end
require("keys").apply(c) require("keys").apply(c)
@ -32,13 +26,12 @@ c.launch_menu = {
} }
c.command_palette_font_size = 13.0 c.command_palette_font_size = 13.0
c.window_frame = { font_size = 13.0 } c.window_frame = { font_size = 13.0 }
c.window_background_opacity = 0.9 c.window_background_opacity = 0.95
wezterm.plugin wezterm.plugin
.require("https://github.com/catppuccin/wezterm") .require("https://github.com/catppuccin/wezterm")
.apply_to_config(c, { .apply_to_config(c, {
flavor = "mocha", sync = true,
sync = utils.is_darwin(),
sync_flavors = { light = "latte", dark = "mocha" }, sync_flavors = { light = "latte", dark = "mocha" },
}) })
wezterm.plugin wezterm.plugin

View file

@ -4,7 +4,6 @@
pkgs, pkgs,
... ...
}: let }: let
inherit (pkgs.stdenv.hostPlatform) isDarwin;
symlink = fileName: {recursive ? false}: { symlink = fileName: {recursive ? false}: {
source = config.lib.file.mkOutOfStoreSymlink "${flakePath}/${fileName}"; source = config.lib.file.mkOutOfStoreSymlink "${flakePath}/${fileName}";
recursive = recursive; recursive = recursive;
@ -26,7 +25,20 @@ in {
sync_frequency = "5m"; sync_frequency = "5m";
}; };
}; };
bat.enable = true; bat = let
themes = pkgs.fetchFromGitHub {
owner = "catppuccin";
repo = "bat";
rev = "ba4d16880d63e656acced2b7d4e034e4a93f74b1";
sha256 = "sha256-6WVKQErGdaqb++oaXnY3i6/GuH2FhTgK0v4TN4Y0Wbw=";
};
in {
enable = true;
themes = {
"Catppuccin-latte" = builtins.readFile (themes + /Catppuccin-latte.tmTheme);
"Catppuccin-mocha" = builtins.readFile (themes + /Catppuccin-mocha.tmTheme);
};
};
btop = { btop = {
enable = true; enable = true;
settings = { settings = {
@ -120,15 +132,18 @@ in {
file = "share/zsh-nix-shell/nix-shell.plugin.zsh"; file = "share/zsh-nix-shell/nix-shell.plugin.zsh";
} }
{ {
src = zsh-fast-syntax-highlighting; src = zsh-fast-syntax-highlighting.overrideAttrs (old: {
src = fetchFromGitHub {
owner = "zdharma-continuum";
repo = "fast-syntax-highlighting";
rev = "cf318e06a9b7c9f2219d78f41b46fa6e06011fd9";
hash = "sha256-RVX9ZSzjBW3LpFs2W86lKI6vtcvDWP6EPxzeTcRZua4=";
};
});
file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh"; file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
} }
]); ]);
shellAliases = { shellAliases = {
cat =
if isDarwin
then "bat --theme=\$(defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo Catppuccin-mocha || echo Catppuccin-latte)"
else "bat";
cp = "cp -i"; cp = "cp -i";
mv = "mv -i"; mv = "mv -i";
rm = "rm -i"; rm = "rm -i";

View file

@ -40,11 +40,12 @@
gtk = true; gtk = true;
}; };
}; };
# needed for gnome3 pinentry
services.dbus.packages = [pkgs.gcr]; # gcr needed for gnome3 pinentry
services.dbus.packages = with pkgs; [darkman gcr];
xdg.portal.enable = true; xdg.portal.enable = true;
xdg.portal.wlr.enable = true; xdg.portal.wlr.enable = true;
xdg.portal.extraPortals = [pkgs.xdg-desktop-portal-gtk]; xdg.portal.extraPortals = with pkgs; [darkman xdg-desktop-portal-gtk];
services = { services = {
# mounting # mounting