nix-config/modules/home/zsh/default.nix

98 lines
2.6 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
2021-03-13 01:02:50 +01:00
let
cfg = config.my.home.zsh;
# Have a nice relative path for XDG_CONFIG_HOME, without leading `/`
relativeXdgConfig =
let
noHome = lib.removePrefix config.home.homeDirectory;
noSlash = lib.removePrefix "/";
in
noSlash (noHome config.xdg.configHome);
2021-03-13 01:02:50 +01:00
in
2021-02-19 19:44:09 +01:00
{
options.my.home.zsh = with lib; {
enable = my.mkDisableOption "zsh configuration";
launchTmux = mkEnableOption "auto launch tmux at shell start";
2021-03-13 01:02:50 +01:00
};
config = lib.mkIf cfg.enable (lib.mkMerge [
{
home.packages = with pkgs; [
zsh-completions
];
programs.zsh = {
enable = true;
dotDir = "${relativeXdgConfig}/zsh"; # Don't clutter $HOME
enableCompletion = true;
2021-02-19 19:44:09 +01:00
history = {
size = 500000;
save = 500000;
extended = true;
expireDuplicatesFirst = true;
ignoreSpace = true;
ignoreDups = true;
share = false;
path = "${config.xdg.dataHome}/zsh/zsh_history";
};
2021-02-19 19:44:09 +01:00
plugins = [
{
name = "fast-syntax-highlighting";
file = "share/zsh/site-functions/fast-syntax-highlighting.plugin.zsh";
src = pkgs.zsh-fast-syntax-highlighting;
}
{
name = "agkozak-zsh-prompt";
file = "share/zsh/site-functions/agkozak-zsh-prompt.plugin.zsh";
src = pkgs.agkozak-zsh-prompt;
}
];
2021-02-19 20:05:15 +01:00
# Modal editing is life, but CLI benefits from emacs gymnastics
defaultKeymap = "emacs";
# Make those happen early to avoid doing double the work
initExtraFirst = ''
${
lib.optionalString cfg.launchTmux ''
# Launch tmux unless already inside one
if [ -z "$TMUX" ]; then
exec tmux new-session
fi
''
}
'';
initExtra = ''
source ${./completion-styles.zsh}
source ${./extra-mappings.zsh}
source ${./options.zsh}
# Source local configuration
if [ -f "$ZDOTDIR/zshrc.local" ]; then
source "$ZDOTDIR/zshrc.local"
fi
'';
localVariables = {
# I like having the full path
AGKOZAK_PROMPT_DIRTRIM = 0;
# Because I *am* from EPITA
AGKOZAK_PROMPT_CHAR = [ "42sh$" "42sh#" ":" ];
# Easy on the eyes
AGKOZAK_COLORS_BRANCH_STATUS = "magenta";
# I don't like moving my eyes
AGKOZAK_LEFT_PROMPT_ONLY = 1;
};
2021-03-30 23:33:42 +02:00
# Enable VTE integration
enableVteIntegration = true;
};
}
]);
2021-02-19 19:44:09 +01:00
}