Compare commits

..
Author SHA1 Message Date
Robby RussellandClaude Opus 5.5 8ee263a828 fix(alias-finder): suggest aliases when the command starts with an alias
The automatic hook searched the command exactly as typed, so `k get pods`
never matched `kgp='kubectl get pods'`. It now searches the alias-expanded
command zsh passes to preexec ($3). When the command started with an alias,
only aliases that cover more of the command are suggested, so typing `gst`
alone still prints nothing.

Closes #12040

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 19:29:14 -08:00
2 changed files with 15 additions and 2 deletions

No files matched your search

+2
View File
@@ -58,6 +58,8 @@ Running the shortest `gs` shell alias that it found:
![image](https://github.com/ohmyzsh/ohmyzsh/assets/19378/39642750-fb10-4f1a-b7f9-f36789eeb01b)
It also looks through aliases you type, suggesting only ones that cover more of the command. With the kubectl plugin, `k get pods` suggests `kgp`, while `kgp` on its own suggests nothing.
### Options
+13 -2
View File
@@ -65,9 +65,20 @@ alias-finder() {
preexec_alias-finder() {
# TODO: Remove backward compatibility (other than zstyle form)
zstyle -t ':omz:plugins:alias-finder' autoload && alias-finder $1 || if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then
alias-finder $1
zstyle -t ':omz:plugins:alias-finder' autoload || [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]] || return
# $3 has aliases expanded, so `k get pods` can suggest `kgp`
local -a words=(${(z)1}) found=(${(f)"$(alias-finder $3)"}) keep
local used=${aliases[$words[1]]} line
# If an alias was typed, only suggest aliases that cover more of the command
if [[ -n "$used" ]]; then
for line in $found; do
(( ${#${(Q)line#*=}} > ${#used} )) && keep+=("$line")
done
found=($keep)
fi
(( $#found )) && print -rl -- $found
}
autoload -U add-zsh-hook