Created
March 28, 2020 07:08
-
-
Save cofirazak/30f1f59d8867c2752e0ac0f5b1757e96 to your computer and use it in GitHub Desktop.
I use oh-my-zsh alias-finder plugin with ZSH_ALIAS_FINDER_AUTOMATIC=true. So i add -l in line 42. That's the equivalent for a wildcard search.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias-finder() { | |
local cmd="" exact="" longer="" wordStart="" wordEnd="" multiWordEnd="" | |
for i in $@; do | |
case $i in | |
-e|--exact) exact=true;; | |
-l|--longer) longer=true;; | |
*) | |
if [[ -z $cmd ]]; then | |
cmd=$i | |
else | |
cmd="$cmd $i" | |
fi | |
;; | |
esac | |
done | |
cmd=$(sed 's/[].\|$(){}?+*^[]/\\&/g' <<< $cmd) # adds escaping for grep | |
if (( $(wc -l <<< $cmd) == 1 )); then | |
while [[ $cmd != "" ]]; do | |
if [[ $longer = true ]]; then | |
wordStart="'{0,1}" | |
else | |
wordEnd="$" | |
multiWordEnd="'$" | |
fi | |
if [[ $cmd == *" "* ]]; then | |
local finder="'$cmd$multiWordEnd" | |
else | |
local finder=$wordStart$cmd$wordEnd | |
fi | |
alias | grep -E "=$finder" | |
if [[ $exact = true || $longer = true ]]; then | |
break | |
else | |
cmd=$(sed -E 's/ {0,1}[^ ]*$//' <<< $cmd) # removes last word | |
fi | |
done | |
fi | |
} | |
preexec_alias-finder() { | |
if [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then | |
alias-finder -l $1 | |
fi | |
} | |
autoload -U add-zsh-hook | |
add-zsh-hook preexec preexec_alias-finder |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment