nixos-config/users/simon/modules/zsh/default.nix

128 lines
3.7 KiB
Nix

{ lib, nixosConfig, pkgs, ... }:
let
solarized = (import ../common.nix).colorschemes.solarized;
dircolors-solarized = pkgs.fetchFromGitHub {
owner = "seebi";
repo = "dircolors-solarized";
rev = "65d4d595ceca96166139862131a006fa3079e00a";
sha256 = "1nl5rs24gi7zqg7nqsbf9fa94yggwzqf3n3imxgfywl8jny3cj1q";
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 ${latitude} ${longitude} | grep -qE '^DAY$' && dynamic-colors switch solarized-light || dynamic-colors switch solarized-dark";
in
{
programs = {
fzf = {
enable = true;
changeDirWidgetCommand = "fd --color always --type d";
changeDirWidgetOptions = [ "--preview 'exa --tree --color=always -L 4 {}'" ];
defaultCommand = "fd --color always";
defaultOptions = [
"--ansi"
"--color=${lib.concatStringsSep
","
(lib.mapAttrsToList
(n: v: "${n}:${v}")
(with solarized; {
"bg" = base03;
"bg+" = base02;
"fg" = base0;
"fg+" = base2;
"header" = blue;
"hl" = blue;
"hl+" = blue;
"info" = yellow;
"marker" = cyan;
"pointer" = cyan;
"prompt" = yellow;
"spinner" = cyan;
}))}"
];
fileWidgetCommand = "fd --color always --type f";
fileWidgetOptions = [ "--preview 'head -n 100 {}'" ];
};
direnv = {
enable = true;
nix-direnv = {
enable = true;
enableFlakes = true;
};
};
nix-index.enable = true;
starship = {
enable = true;
settings = {
add_newline = false;
};
};
zsh = {
enable = true;
history = {
save = 100000;
size = 100000;
};
plugins = [
{
name = "zsh-nix-shell";
file = "nix-shell.plugin.zsh";
src = "${pkgs.zsh-nix-shell}/share/zsh-nix-shell";
}
];
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";
ip = "ip --color=auto";
ipy = "ipython3";
l = "exa -l";
la = "exa -la";
ll = "exa -l";
ls = "exa";
userctl = "systemctl --user";
vim = "nvim";
vimdiff = "nvim -d";
};
initExtraFirst = ''
# automatic color scheme
${dcauto}
'';
initExtra = lib.mkMerge [
(lib.mkBefore ''
prompt off # collides with starship
'')
(lib.mkAfter /* sh */ ''
eval $(${pkgs.coreutils}/bin/dircolors -b ${dircolors-solarized}/dircolors.ansi-universal)
# no sad smiley (starship shows exit status)
zstyle ':prompt:grml:right:setup' items
# do not glob # (conflicts with nix flakes)
disable -p '#'
# ^X^E to edit current command
autoload -z edit-command-line
zle -N edit-command-line
bindkey "^X^E" edit-command-line
# syntax highlighting
source ${pkgs.zsh-fast-syntax-highlighting}/share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh
FAST_HIGHLIGHT_STYLES[comment]=fg=010
source ${./pass-wrappers.zsh}
'')
];
};
};
}