dotfiles/home-manager/modules/zsh.nix

111 lines
2.7 KiB
Nix
Raw Normal View History

2022-09-26 22:50:43 +00:00
{ config, pkgs, lib, libs, ... }:
{
programs.zsh = {
enable = true;
enableCompletion = false;
dotDir = ".config/zsh";
shellAliases = {
2022-09-27 06:41:43 +00:00
fetch = "git fetch --all --jobs=4 --progress --prune";
2022-09-26 22:50:43 +00:00
run = "./run";
2022-09-27 06:41:43 +00:00
pull = "git pull --autostash --jobs=4 --summary origin";
rebase = "git rebase --autostash --stat";
update = "fetch && rebase";
2022-09-26 22:50:43 +00:00
};
initExtra = ''
# Make Caps Lock behave like Ctrl.
setxkbmap -option ctrl:nocaps
# Make short-pressed Ctrl behave like Escape.
xcape -e 'Control_L=Escape'
2023-03-22 22:26:30 +00:00
# Plugins
source "''${ZPLUG_REPOS}/robbyrussell/oh-my-zsh/plugins/git/git.plugin.zsh"
source "''${ZPLUG_REPOS}/robbyrussell/oh-my-zsh/plugins/vi-mode/vi-mode.plugin.zsh"
2022-10-12 06:59:47 +00:00
2022-09-26 22:50:43 +00:00
# Case insensitive autocompletion.
zstyle ":completion:*" matcher-list "" "m:{a-zA-Z}={A-Za-z}" "r:|=*" "l:|=* r:|=*"
autoload -Uz compinit && compinit
clear-ls-all() {
clear
exa -al
}
zle -N clear-ls-all
bindkey '^K' clear-ls-all
clear-git-status() {
clear
git status -sb .
}
zle -N clear-git-status
bindkey '^G' clear-git-status
# auto-completes aliases
# enables to define
# - normal aliases (completed with trailing space)
# - blank aliases (completed without space)
# - ignored aliases (not completed)
# ignored aliases
typeset -a ialiases
ialiases=()
ialias() {
alias $@
args="$@"
args=''${args%%\=*}
ialiases+=(''${args##* })
}
# blank aliases
typeset -a baliases
baliases=()
balias() {
alias $@
args="$@"
args=''${args%%\=*}
baliases+=(''${args##* })
}
expand-alias-space() {
[[ $LBUFFER =~ "\<(''${(j:|:)baliases})\$" ]]; insertBlank=$?
if [[ ! $LBUFFER =~ "\<(''${(j:|:)ialiases})\$" ]]; then
zle _expand_alias
fi
zle self-insert
if [[ "$insertBlank" = "0" ]]; then
zle backward-delete-char
fi
}
zle -N expand-alias-space
bindkey " " expand-alias-space
bindkey -M isearch " " magic-space
2023-01-08 08:38:12 +00:00
setopt auto_cd
setopt auto_pushd
setopt pushd_ignore_dups
setopt pushdminus
2022-09-26 22:50:43 +00:00
'';
zplug = {
enable = true;
plugins = [
2023-03-22 22:26:30 +00:00
{ name = "plugin/git"; tags = [from:oh-my-zsh]; }
{ name = "plugin/vi-mode"; tags = [from:oh-my-zsh]; }
2022-09-26 22:50:43 +00:00
{ name = "mollifier/cd-gitroot"; }
{ name = "zsh-users/zsh-autosuggestions"; }
{ name = "zsh-users/zsh-completions"; }
{ name = "zsh-users/zsh-syntax-highlighting"; }
];
};
};
}