mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-12-02 13:23:05 +01:00
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>
This commit is contained in:
1 parent
44a5decbc4
commit
8ee263a828
2 files changed
+15
-2
No files matched your search
@@ -58,6 +58,8 @@ Running the shortest `gs` shell alias that it found:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
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
|
### Options
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,20 @@ alias-finder() {
|
|||||||
|
|
||||||
preexec_alias-finder() {
|
preexec_alias-finder() {
|
||||||
# TODO: Remove backward compatibility (other than zstyle form)
|
# 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
|
zstyle -t ':omz:plugins:alias-finder' autoload || [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]] || return
|
||||||
alias-finder $1
|
|
||||||
|
# $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
|
fi
|
||||||
|
(( $#found )) && print -rl -- $found
|
||||||
}
|
}
|
||||||
|
|
||||||
autoload -U add-zsh-hook
|
autoload -U add-zsh-hook
|
||||||
|
|||||||
Reference in new issue
Block a user