From 974a4b7f490fcc000a52e7adf8d3754620e82f52 Mon Sep 17 00:00:00 2001 From: Jamie Quigley Date: Sat, 22 Jan 2022 16:27:10 +0000 Subject: [PATCH] Zsh: Fix globalias expansion See: https://github.com/chisui/zsh-nix-shell/issues/31 Also update globalias from upstream. --- zsh-plugins/globalias.plugin.zsh | 25 +++++++++++++++++++------ zshrc | 20 ++++++++------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/zsh-plugins/globalias.plugin.zsh b/zsh-plugins/globalias.plugin.zsh index 80b8dde..bd27d58 100644 --- a/zsh-plugins/globalias.plugin.zsh +++ b/zsh-plugins/globalias.plugin.zsh @@ -1,10 +1,23 @@ globalias() { - zle _expand_alias - zle self-insert + # Get last word to the left of the cursor: + # (z) splits into words using shell parsing + # (A) makes it an array even if there's only one element + local word=${${(Az)LBUFFER}[-1]} + if [[ $GLOBALIAS_FILTER_VALUES[(Ie)$word] -eq 0 ]]; then + zle _expand_alias + zle expand-word + fi + zle self-insert } - zle -N globalias -bindkey " " magic-space -bindkey "^ " globalias -bindkey -M isearch " " magic-space # normal space during searches +# space expands all aliases, including global +bindkey -M emacs " " globalias +bindkey -M viins " " globalias + +# control-space to make a normal space +bindkey -M emacs "^ " magic-space +bindkey -M viins "^ " magic-space + +# normal space during searches +bindkey -M isearch " " magic-space diff --git a/zshrc b/zshrc index 5c992f8..3f93369 100644 --- a/zshrc +++ b/zshrc @@ -169,24 +169,12 @@ fi eval $(ssh-agent) >/dev/null # Plugins -if [ -f ~/.zsh/plugins/globalias.plugin.zsh ]; then - source ~/.zsh/plugins/globalias.plugin.zsh -else - echo "globalias plugin not loaded" -fi - if [ -f ~/.zsh/plugins/git.plugin.zsh ]; then source ~/.zsh/plugins/git.plugin.zsh else echo "git plugin not loaded" fi -if [ -f ~/.zsh/plugins/you-should-use.plugin.zsh ]; then - source ~/.zsh/plugins/you-should-use.plugin.zsh -else - echo "you-should-use plugin not loaded" -fi - if [ -f ~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then source ~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh else @@ -223,6 +211,14 @@ else echo "zsh-nix-shell plugin not loaded" fi +if [ -f ~/.zsh/plugins/globalias.plugin.zsh ]; then + source ~/.zsh/plugins/globalias.plugin.zsh + GLOBALIAS_FILTER_VALUES=(ls lsa lsat lstg vim rm cp) +else + echo "globalias plugin not loaded" +fi + + if type atuin >/dev/null; then autoload -U add-zsh-hook