dotfiles/home/apps/colorscheme-sync.nix

62 lines
1.8 KiB
Nix
Raw Normal View History

2023-07-13 08:45:39 +02:00
{
config,
2023-11-28 12:21:17 +01:00
lib,
2023-07-13 08:45:39 +02:00
pkgs,
...
}: let
# TODO: de-duplicate across modules
lat = 48.210033;
lng = 16.363449;
2023-11-28 12:21:17 +01:00
inherit (pkgs.stdenv) isDarwin isLinux;
2023-07-13 08:45:39 +02:00
in {
2023-11-28 12:21:17 +01:00
config = lib.mkIf config.isGraphical {
home.packages = [
(pkgs.writeShellApplication {
name = "dark-mode-ternary";
runtimeInputs = [pkgs.gnugrep];
text = let
queryCommand =
if isLinux
then "dbus-send --session --print-reply=literal --reply-timeout=5 --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 isDarwin
then "defaults read -g AppleInterfaceStyle &>/dev/null"
else throw "Unsupported platform";
in ''
[[ -z "''${1-}" ]] && [[ -z "''${2-}" ]] && echo "Usage: $0 <dark> <light>" && exit 1
2023-07-13 08:45:39 +02:00
2023-11-28 12:21:17 +01:00
if ${queryCommand}; then
echo "$1"
else
echo "$2"
fi
'';
})
];
2023-07-13 08:45:39 +02:00
2023-11-28 12:21:17 +01:00
services.darkman = let
starship = "${config.programs.starship.package}/bin/starship";
zsh = "${config.programs.zsh.package}/bin/zsh";
in {
enable = isLinux;
settings = {
inherit lat lng;
useGeoclue = false;
};
darkModeScripts = {
toggle-shell = ''
${starship} config palette catppuccin_mocha
${zsh} -ic "fast-theme XDG:catppuccin-mocha"
'';
};
lightModeScripts = {
toggle-shell = ''
${starship} config palette catppuccin_latte
${zsh} -ic "fast-theme XDG:catppuccin-latte"
'';
};
2023-07-13 08:45:39 +02:00
};
2023-11-28 12:21:17 +01:00
programs.zsh.shellAliases.cat = "bat --theme=$(dark-mode-ternary 'Catppuccin-mocha' 'Catppuccin-latte')";
};
2023-07-13 08:45:39 +02:00
}