From a67ec1b22f90c2d7c852dfde548d313ae2231db6 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 25 Jul 2021 08:58:57 +0200 Subject: [PATCH] zsh: Automatically set color scheme at init --- users/simon/modules/zsh/default.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/users/simon/modules/zsh/default.nix b/users/simon/modules/zsh/default.nix index 11e5c62..29fff36 100644 --- a/users/simon/modules/zsh/default.nix +++ b/users/simon/modules/zsh/default.nix @@ -1,4 +1,4 @@ -{ lib, pkgs, ... }: +{ lib, nixosConfig, pkgs, ... }: let dircolors-solarized = pkgs.fetchFromGitHub { owner = "seebi"; @@ -8,6 +8,14 @@ let meta.license = lib.licenses.mit; }; + + # automatically set color scheme based on sun with dynamic-colors + dcauto = + let + latitude = (toString nixosConfig.location.latitude) + (if nixosConfig.location.latitude > 0 then "N" else "S"); + longitude = (toString nixosConfig.location.longitude) + (if nixosConfig.location.longitude > 0 then "E" else "W"); + in + "${pkgs.sunwait}/bin/sunwait poll civil ${latitude} ${longitude} | grep -qE '^DAY$' && dynamic-colors switch solarized-light || dynamic-colors switch solarized-dark"; in { programs = { @@ -53,6 +61,7 @@ in ]; shellAliases = { cp = "cp --reflink=auto"; # TODO: remove with coreutils > 8.32 + dcauto = dcauto; dcsd = "dynamic-colors switch solarized-dark"; dcsl = "dynamic-colors switch solarized-light"; exa = "exa --git --binary"; @@ -66,6 +75,10 @@ in vim = "nvim"; vimdiff = "nvim -d"; }; + initExtraFirst = '' + # automatic color scheme + ${dcauto} + ''; initExtra = lib.mkMerge [ (lib.mkBefore '' prompt off # collides with starship