Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
Zsh: Fix globalias expansion
Browse files Browse the repository at this point in the history
See: chisui/zsh-nix-shell#31

Also update globalias from upstream.
  • Loading branch information
Sciencentistguy committed Jan 25, 2022
1 parent d4d775e commit 974a4b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
25 changes: 19 additions & 6 deletions zsh-plugins/globalias.plugin.zsh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 8 additions & 12 deletions zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 974a4b7

Please sign in to comment.