1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-10-24 05:33:45 +08:00
Files
ohmyzsh/plugins/globalias/globalias.plugin.zsh
Kunpeng Xie eb29cdb33a fix(globalias): preserve quoted words and assignment values (#14092)
Only invoke alias completion when the complete shell word is an alias name. Completion otherwise treats assignment values and quoted text as standalone alias names, corrupting inputs such as DEBUG=1.

Add a real ZLE regression test covering the reported assignments, quotes, escaped aliases, filtering, and existing expansion behavior.

Assisted-by: OpenAI Codex
2026-10-11 15:58:22 -07:00

28 lines
862 B
Bash

globalias() {
# 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
# Completion also considers quoted strings and assignment values as aliases.
# Only expand when the complete shell word is an alias name.
if (( ${+aliases[$word]} || ${+galiases[$word]} )); then
zle _expand_alias
fi
zle expand-word
fi
zle self-insert
}
zle -N globalias
# 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