nixos-config/modules/programs/zsh/default.nix

117 lines
3.6 KiB
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.ptw.programs.zsh;
in {
options.ptw.programs.zsh = {
enable = lib.mkEnableOption "Enable and configure zsh using HomeManager";
};
config = lib.mkIf cfg.enable {
environment = {
systemPackages = [ pkgs.zsh ];
shells = [ pkgs.zsh ];
pathsToLink = [ "/share/zsh" ];
};
# Otherwise the user won't appear on the GDM login screen
programs.zsh.enable = true;
home-manager.users."${config.ptw.system.singleUser}".programs.zsh = {
enable = true;
history.ignoreSpace = true;
shellAliases = let
home = "/home/${config.ptw.system.singleUser}/Development/Personal/nixos-config";
nixosSwitch = "nixos-rebuild --flake .#${config.ptw.system.hostName} switch --use-remote-sudo";
in {
ls = "ls --color=always";
".." = "cd ..";
"..." = "cd ../../";
dev = "cd $HOME/Development";
home = "cd $HOME";
reload = "$SHELL -l";
gs = "git status";
gd = "git diff";
gds = "git diff --staged";
c = "clear";
suspend = "systemctl suspend";
nixos-rebuild-switch = "pushd; cd ${home}; ${nixosSwitch}; popd";
nixos-rebuild-switch-fast = "pushd; cd ${home}; ${nixosSwitch} --fast; popd";
waifu2x = "flatpak run com.github.nihui.waifu2x-ncnn-vulkan";
};
initExtra = ''
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey "\e[3~" delete-char
'';
history.share = true;
initExtraFirst = let
enableDirenv = lib.optionalString
config.ptw.programs.direnv.enable
"eval \"$(${pkgs.direnv}/bin/direnv hook zsh)\"";
in ''
${enableDirenv}
# TODO: Maybe move this somewhere else
wcurl() {
[[ -z "$1" ]] && echo "Error: No URL specified" && exit 1
local filename="$(basename $1)"
curl -fLo "$filename" "$1"
}
'';
plugins = [
{
name = "pure.zsh";
file = "pure.zsh";
src = pkgs.fetchFromGitHub {
owner = "sindresorhus";
repo = "pure";
rev = "v1.17.0";
sha256 = "0qfs7rvpyd8jb7x4ziqrkh0b6g9ldds8sn6qbqgrir80vdk90gpa";
};
}
{
name = "zsh-history-substring-search";
src = pkgs.fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-history-substring-search";
rev = "0f80b8eb3368b46e5e573c1d91ae69eb095db3fb";
sha256 = "0y8va5kc2ram38hbk2cibkk64ffrabfv1sh4xm7pjspsba9n5p1y";
};
}
{
name = "completion";
file = "init.zsh";
src = pkgs.fetchFromGitHub {
owner = "zimfw";
repo = "completion";
rev = "db079f405397a9dc9af93883e47d8adff817e3b1";
sha256 = "1vakjj8l10discmzrzjq6nd0bg0jf4chxhwpiq7ldkirzy7lmm9c";
};
}
{
name = "zsh-completions";
src = pkgs.fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-completions";
rev = "d4511c23659381b56dec8be8c8553b7ff3dc5fd8";
sha256 = "1y8wkmhgkkyfz91y1f8crh6cg912n87gmcchc8xhnwji11n1mqrq";
};
}
{
name = "zsh-syntax-highlighting";
src = pkgs.fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-syntax-highlighting";
rev = "c5ce0014677a0f69a10b676b6038ad127f40c6b1";
sha256 = "sha256-UqeK+xFcKMwdM62syL2xkV8jwkf/NWfubxOTtczWEwA=";
};
}
];
};
};
}