niksos/modules/cli/zsh.nix
2024-06-07 21:19:52 +02:00

104 lines
3.5 KiB
Nix

{
config,
lib,
pkgs,
...
}: let
cfg = config.myOptions.programs.zsh;
inherit (config.myOptions.other.system) username;
inherit (lib) mkEnableOption mkIf mkOption;
inherit (lib.types) attrs bool;
in {
options.myOptions.programs.zsh = {
enable = mkEnableOption "zsh";
extraAliases = mkOption {
type = attrs;
description = "extra shell aliases";
default = {};
};
profiling = mkOption {
type = bool;
description = "enable zsh profiling";
default = false;
};
};
config = mkIf cfg.enable {
programs.zsh.enable = true;
users.users.${username}.shell = pkgs.zsh;
environment = {
shells = [ pkgs.zsh ];
pathsToLink = [ "/share/zsh" ];
};
home-manager.users.${username} = {
# for fzf-tab
home.packages = [ pkgs.fzf ];
programs.zsh = {
enable = true;
shellAliases = {
cl = "clear";
cp = "cp -ivr";
mv = "mv -iv";
rm = "trash -v";
l = "eza --icons -a";
e = "eza --icons -lha --git";
untar = "tar -xvf";
untargz = "tar -xzf";
mnt = "udisksctl mount -b";
umnt = "udisksctl unmount -b";
v = "nvim";
kys = "shutdown now";
gpl = "curl https://www.gnu.org/licenses/gpl-3.0.txt -o LICENSE";
agpl = "curl https://www.gnu.org/licenses/agpl-3.0.txt -o LICENSE";
g = "git";
n = "nix";
woman = "man";
open = "xdg-open";
":q" = "exit";
emacs = ":(){ :|:& };:";
m = "make";
sys = "systemctl";
} // cfg.extraAliases;
initExtraFirst = mkIf cfg.profiling "zmodload zsh/zprof";
initExtra = mkIf cfg.profiling "zprof";
history = {
path = "${config.home-manager.users.${username}.xdg.dataHome}/zsh/zsh_history";
size = 9999999999;
save = 9999999999;
extended = true;
ignoreSpace = true;
};
autosuggestion.enable = true;
enableCompletion = true;
autocd = false;
dotDir = ".config/zsh";
plugins = [
{
name = "zsh-fast-syntax-highlighting";
file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
src = pkgs.zsh-fast-syntax-highlighting;
}
{
name = "zsh-nix-shell";
file = "share/zsh-nix-shell/nix-shell.plugin.zsh";
src = pkgs.zsh-nix-shell;
}
{
name = "zsh-fzf-tab";
file = "share/fzf-tab/fzf-tab.plugin.zsh";
src = pkgs.zsh-fzf-tab;
}
{
name = "zsh-vi-mode";
file = "share/zsh-vi-mode/zsh-vi-mode.plugin.sh";
src = pkgs.zsh-vi-mode;
}
];
};
};
};
}