From 4fa13eb463971dd070fe54236bd47c5846b8ba44 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Sun, 23 Mar 2025 22:48:18 +0900 Subject: [PATCH 1/7] chore(alias-finder): Refactor add-zsh-hook part --- plugins/alias-finder/alias-finder.plugin.zsh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index 5fdfbc835..3ed1dbb0a 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -51,12 +51,14 @@ alias-finder() { done } +# add hook to run alias-finder before each command 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 - fi + alias-finder "$1" } - -autoload -U add-zsh-hook -add-zsh-hook preexec preexec_alias-finder +if zstyle -t ':omz:plugins:alias-finder' autoload ; then + autoload -Uz alias-finder + add-zsh-hook preexec preexec_alias-finder +elif [[ $ZSH_ALIAS_FINDER_AUTOMATIC = true ]]; then # TODO: remove this legacy style support + autoload -Uz alias-finder + add-zsh-hook preexec preexec_alias-finder +fi From d860c7548f05621c9df8fe315a8d68eae2c9c8c7 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Sun, 23 Mar 2025 23:44:51 +0900 Subject: [PATCH 2/7] doc(alias-finder): Add note for defect in option settings --- plugins/alias-finder/alias-finder.plugin.zsh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index 3ed1dbb0a..a97bf94c2 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -1,19 +1,18 @@ alias-finder() { - local cmd=" " exact="" longer="" cheaper="" wordEnd="'{0,1}$" finder="" filter="" + local cmd=" " exact=false longer=false cheaper=false wordEnd="'?$" finder="" filter="" - # build command and options + # setup options + # XXX: This logic has flaw. If user enable options with zstyle, there's no way to disable it. + # It's because same function is used for autoload hook and manual execution. + # I believe manual execution is very minor in use, so I'll keep it as is for now. for c in "$@"; do case $c in - # TODO: Remove backward compatibility (other than zstyle form) - # set options if exist -e|--exact) exact=true;; -l|--longer) longer=true;; -c|--cheaper) cheaper=true;; - # concatenate cmd *) cmd="$cmd$c " ;; esac done - zstyle -t ':omz:plugins:alias-finder' longer && longer=true zstyle -t ':omz:plugins:alias-finder' exact && exact=true zstyle -t ':omz:plugins:alias-finder' cheaper && cheaper=true From 3a746a7ee152d923812487987a7a0e9618ea7f02 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Sun, 23 Mar 2025 23:46:04 +0900 Subject: [PATCH 3/7] refactor(alias-finder): Simplify --longer option activation --- plugins/alias-finder/alias-finder.plugin.zsh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index a97bf94c2..19f747f4b 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -24,9 +24,7 @@ alias-finder() { ## - add escaping character to special characters cmd=$(echo -n "$cmd" | tr '\n' ' ' | xargs | tr -s '[:space:]' | sed 's/[].\|$(){}?+*^[]/\\&/g') - if [[ $longer == true ]]; then - wordEnd="" # remove wordEnd to find longer aliases - fi + $longer && wordEnd=".*$" # find with alias and grep, removing last word each time until no more words while [[ $cmd != "" ]]; do From 129790826552fcc6f1b3c8f3dd776c6134d99308 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Sun, 23 Mar 2025 23:47:32 +0900 Subject: [PATCH 4/7] fix(alias-finder): Add missing closing single quote for cheaper option --- plugins/alias-finder/alias-finder.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index 19f747f4b..93952664b 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -33,7 +33,7 @@ alias-finder() { # make filter to find only shorter results than current cmd if [[ $cheaper == true ]]; then cmdLen=$(echo -n "$cmd" | wc -c) - filter="^'{0,1}.{0,$((cmdLen - 1))}=" + filter="^'?.{1,$((cmdLen - 1))}'?=" # some aliases is surrounded by single quotes fi alias | grep -E "$filter" | grep -E "=$finder" From 3b550a69f6f9bc2c8466458a8dea6e5d5c93c491 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Sun, 23 Mar 2025 23:49:46 +0900 Subject: [PATCH 5/7] refactor(alias-finder): Simplify --exact option activation --- plugins/alias-finder/alias-finder.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index 93952664b..a9ef132f2 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -38,9 +38,9 @@ alias-finder() { alias | grep -E "$filter" | grep -E "=$finder" - if [[ $exact == true ]]; then - break # because exact case is only one - elif [[ $longer = true ]]; then + $exact && break # because exact case is only one + + if [[ $longer = true ]]; then break # because above grep command already found every longer aliases during first cycle fi From 92fb85e498d80ea341d15225641d774d8edebce8 Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Mon, 24 Mar 2025 00:00:12 +0900 Subject: [PATCH 6/7] refactor(alias-finder): Add meaningful variable name for finder variable part --- plugins/alias-finder/alias-finder.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index a9ef132f2..a4c1d2423 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -1,5 +1,5 @@ alias-finder() { - local cmd=" " exact=false longer=false cheaper=false wordEnd="'?$" finder="" filter="" + local cmd=" " exact=false longer=false cheaper=false wordStart="^'?" wordEnd="'?$" finder="" filter="" # setup options # XXX: This logic has flaw. If user enable options with zstyle, there's no way to disable it. @@ -28,7 +28,7 @@ alias-finder() { # find with alias and grep, removing last word each time until no more words while [[ $cmd != "" ]]; do - finder="'{0,1}$cmd$wordEnd" + finder="$wordStart$cmd$wordEnd" # make filter to find only shorter results than current cmd if [[ $cheaper == true ]]; then From f3d7b15cb33b7adab12d804df4e154486d4d086a Mon Sep 17 00:00:00 2001 From: Roeniss Moon Date: Mon, 24 Mar 2025 00:15:07 +0900 Subject: [PATCH 7/7] refactor(alias-finder): Simplify --longer option activation --- plugins/alias-finder/alias-finder.plugin.zsh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/plugins/alias-finder/alias-finder.plugin.zsh b/plugins/alias-finder/alias-finder.plugin.zsh index a4c1d2423..09da9849c 100644 --- a/plugins/alias-finder/alias-finder.plugin.zsh +++ b/plugins/alias-finder/alias-finder.plugin.zsh @@ -39,10 +39,7 @@ alias-finder() { alias | grep -E "$filter" | grep -E "=$finder" $exact && break # because exact case is only one - - if [[ $longer = true ]]; then - break # because above grep command already found every longer aliases during first cycle - fi + $longer && break # because above grep command already found every longer aliases during first cycle cmd=$(sed -E 's/ {0,}[^ ]*$//' <<< "$cmd") # remove last word done