nix/modules/home-manager/cli/zsh/default.nix

117 lines
3.5 KiB
Nix

{ lib, config, pkgs, ... }:
with lib;
let
cfg = config.modules.cli.zsh;
in
{
options.modules.cli.zsh = {
enable = mkEnableOption "enable Zsh configuration";
};
config = mkIf cfg.enable {
programs.zsh = {
enable = true;
dotDir = ".config/zsh";
defaultKeymap = "viins";
enableCompletion = true;
history = {
ignoreAllDups = true;
save = 10000;
share = true;
path = "$HOME/.local/share/zsh/history";
};
historySubstringSearch = {
enable = true;
searchDownKey = "^[OB";
searchUpKey = "^[OA";
};
syntaxHighlighting = {
enable = true;
highlighters = [ "brackets" "main" "pattern" ];
styles = {
builtin = "fg=#7cafc2,bold";
single-hyphen-option = "fg=#86c1b9";
double-hyphen-option = "fg=#86c1b9";
back-quoted-argument-delimiter = "fg=ba8baf,bold";
single-quoted-argument = "fg=f7ca88";
function = "fg=blue";
reserved-word = "fg=#ba8baf,bold";
assign = "fg=#a1b56c";
bracket-level-1 = "fg=7cafc2";
bracket-level-2 = "fg=ba8baf";
bracket-level-3 = "fg=#a1b56c";
bracket-error = "fg=#ab4642,bold";
cursor-matchingbracket = "fg=ba8baf,bold";
redirection = "fg=#f7ca88,bold";
back-double-quoted-argument = "fg=#7cafc2";
dollar-double-quoted-argument = "fg=#86c1b9";
};
patterns = {
"\\|" = "fg=#f7ca88,bold";
" \\|\\| " = "fg=ba8baf,bold";
" \\&\\& " = "fg=ba8baf,bold";
"\\n" = "fg=#7cafc2";
};
};
initExtra = ''
# Ctrl + backspace: delete word
bindkey -v "^H" backward-kill-word
bindkey -v "^b" backward-word
bindkey -v "^e" forward-word
bindkey -v "^u" backward-kill-line
bindkey -v "^[^u" kill-line
bindkey -v "^w" backward-kill-word
bindkey -v "^[^w" kill-word
## Edit command line with nvim
autoload -z edit-command-line
zle -N edit-command-line
bindkey -a v edit-command-line
# change cursor like vim does
zle-keymap-select () {
if [[ ''$KEYMAP == vicmd ]]; then
# the command mode for vi
echo -ne "\e[2 q"
else
# the insert mode for vi
echo -ne "\e[5 q"
fi
}
precmd_functions+=(zle-keymap-select)
zle -N zle-keymap-select
'';
completionInit = ''
autoload -Uz compinit
for dump in ''${ZDOTDIR}/.zcompdump(N.mh+24); do
compinit
done
compinit -C
'';
plugins = [
{
name = "base16-shell";
src = pkgs.fetchFromGitHub {
owner = "chriskempson";
repo = "base16-shell";
rev = "588691ba71b47e75793ed9edfcfaa058326a6f41";
hash = "sha256-X89FsG9QICDw3jZvOCB/KsPBVOLUeE7xN3VCtf0DD3E=";
};
}
{
name = "history-search-multi-word";
src = pkgs.fetchFromGitHub {
owner = "zdharma-continuum";
repo = "history-search-multi-word";
rev = "c4dcddc1cd17e7e0909471703f3526170db0f475";
hash = "sha256-KgKm9qzFnwXDXwmTruPgC0tjmiTY5AiGdrWW4zDWUF4=";
};
}];
localVariables = {
BASE16_THEME = "$HOME/.config/zsh/plugins/base16";
# Make ESC key more reactive to go to normal mode
KEYTIMEOUT = 1;
};
};
};
}