nixos/modules/home/zsh/default.nix

102 lines
2.6 KiB
Nix

{
config,
lib,
osConfig,
pkgs,
...
}:
with lib;
let
cfg = osConfig.modules.zsh;
xdgCfg = config.xdg;
in
{
imports = [
./completion.nix
./p10k.nix
];
programs.zsh = {
enable = cfg.enable;
dotDir = "${xdgCfg.configHome}/zsh";
autosuggestion.enable = false;
enableCompletion = false;
syntaxHighlighting = {
enable = true;
highlighters = [
"main"
"brackets"
"pattern"
"root"
];
};
historySubstringSearch.enable = true;
history = {
append = true;
ignoreDups = false;
ignoreSpace = true;
save = 100000;
share = true;
size = 100000;
extended = true;
};
initContent =
let
zshConfigInitEarly = mkOrder 500 ''
# p10k
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh" ]]; then
source "''${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-''${(%):-%n}.zsh"
fi
source "${xdgCfg.configHome}/zsh/p10k.zsh";
'';
zshConfig = mkOrder 1000 ''
# Autocompletion and menu styling
zmodload zsh/complist
autoload -Uz compinit && compinit
source "${xdgCfg.configHome}/zsh/completion.zsh";
# vi keybindings for menu select
bindkey -M menuselect 'h' vi-backward-char
bindkey -M menuselect 'k' vi-up-line-or-history
bindkey -M menuselect 'j' vi-down-line-or-history
bindkey -M menuselect 'l' vi-forward-char
# Tab to accept current selection
bindkey -M menuselect '^I' accept-and-infer-next-history
# Control arrow keys
bindkey '^[[1;5C' forward-word
bindkey '^[[1;5D' backward-word
'';
in mkMerge [ zshConfigInitEarly zshConfig ];
shellAliases = {
".." = "cd ..";
"..." = "cd ../..";
ls = "ls --color=auto";
ll = "ls -al";
grep = "grep --color=auto";
back = "cd $OLDPWD";
gs = "git status";
ssha = "eval $(ssh-agent) && ssh-add";
};
plugins = [
{
name = "powerlevel10k";
src = "${pkgs.zsh-powerlevel10k}/share/zsh-powerlevel10k/";
file = "powerlevel10k.zsh-theme";
}
{
name = "zsh-autocomplete";
src = "${pkgs.zsh-autocomplete}/share/zsh-autocomplete/";
file = "zsh-autocomplete.zsh";
}
];
};
}