Oliver Davies
ac0c71775d
Automatically expand aliases after the space key is pressed, unless it was added using the `ialias` function. This is something that I saw on Sebastian Daschner's videos (https://www.sebastian-daschner.com, https://www.youtube.com/@SebastianDaschnerIT) and is from his dotfiles (https://github.com/sdaschner/dotfiles).
118 lines
2.6 KiB
Nix
118 lines
2.6 KiB
Nix
{ config, pkgs, lib, libs, ... }:
|
|
{
|
|
programs.zsh = {
|
|
enable = true;
|
|
enableCompletion = false;
|
|
dotDir = ".config/zsh";
|
|
|
|
shellAliases = {
|
|
fetch = "git fetch --all --jobs=4 --progress --prune";
|
|
run = "./run";
|
|
pull = "git pull --autostash --jobs=4 --summary origin";
|
|
rebase = "git rebase --autostash --stat";
|
|
update = "fetch && rebase";
|
|
};
|
|
|
|
initExtra = ''
|
|
if [ -f ~/.config/zsh/.p10k.zsh ]; then
|
|
. ~/.config/zsh/.p10k.zsh
|
|
fi
|
|
|
|
eval "$(zoxide init zsh)"
|
|
|
|
# Case insensitive autocompletion.
|
|
zstyle ":completion:*" matcher-list "" "m:{a-zA-Z}={A-Za-z}" "r:|=*" "l:|=* r:|=*"
|
|
autoload -Uz compinit && compinit
|
|
|
|
# No arguments: `git status`
|
|
# With arguments: acts like `git`
|
|
g() {
|
|
if [[ $# -gt 0 ]]; then
|
|
git "$@"
|
|
else
|
|
git status
|
|
fi
|
|
}
|
|
|
|
compdef g=git
|
|
|
|
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
|
|
|
|
setopt auto_cd
|
|
setopt auto_pushd
|
|
setopt pushd_ignore_dups
|
|
setopt pushdminus
|
|
'';
|
|
|
|
zplug = {
|
|
enable = true;
|
|
|
|
plugins = [
|
|
{ name = "mollifier/cd-gitroot"; }
|
|
{ name = "romkatv/powerlevel10k"; tags = [ as:theme depth:1 ]; }
|
|
{ name = "zsh-users/zsh-autosuggestions"; }
|
|
{ name = "zsh-users/zsh-completions"; }
|
|
{ name = "zsh-users/zsh-syntax-highlighting"; }
|
|
];
|
|
};
|
|
};
|
|
}
|