MichaelAquilina / zsh-you-should-use

📎 ZSH plugin that reminds you to use existing aliases for commands you just typed
GNU General Public License v3.0
1.42k stars 44 forks source link

Some shorter aliases are not detected #79

Open benwaffle opened 4 years ago

benwaffle commented 4 years ago

Issue Details

Please provide the following details when opening an issue:

Operating System (uname -a)

Darwin MacBook-Pro 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

zsh version (zsh --version)

zsh 5.7.1 (x86_64-apple-darwin18.2.0)

you-should-use version (echo "$YSU_VERSION")

1.3.0

How is zsh-you-should-use installed?

Steps to reproduce the issue

  1. Make sure oh-my-zsh is installed
  2. Run gd --word-diff
  3. See that gdw is not recommended

Based on alias gd='git diff' and alias gdw='git diff --word-diff', I think that running gd --word-diff should recommend gdw.

MichaelAquilina commented 4 years ago

I'm afraid this issue went past my radar without me noticing! Would you please mind posting your alias definitions to see if I can easily reproduce the issue on my machine?

MichaelAquilina commented 4 years ago

@benwaffle polite ping about this (I can't seem to reproduce this)

MichaelAquilina commented 4 years ago

@benwaffle take a look at the latest release (1.5.0). The issue should be fixed there. Thanks for reporting the issue!

MichaelAquilina commented 4 years ago

Re-opening this issue as the feature that solved it has been reverted.

Aloxaf commented 4 years ago

Emmm, why the fix was reverted?

MichaelAquilina commented 4 years ago

The way the feature was implemented introduced a number of bugs. This problem is actually a lot harder than it looks to solve and will require quite a bit of thinking.

NightMachinery commented 4 years ago

@MichaelAquilina Can you check out how https://github.com/djui/alias-tips solves this? (Search for Disable Command Expansion on that page)

I use this little function to expand aliases, can't it solve this?

expand-aliases () {
    # 'See https://unix.stackexchange.com/questions/372811/better-understand-a-function-expanding-aliases-in-zsh'
    unset 'functions[_expand-aliases]'
    functions[_expand-aliases]="$@"
    (($+functions[_expand-aliases])) && print -r -- "${functions[_expand-aliases]#$'\t'}"
}
MDHD-Yee commented 4 years ago

@MichaelAquilina Besides, sometimes if there exist multiple aliases for the same command, this plugin can not find the shortest one.

$ alias abc=abcd ab=abcd
$ abcd
Found existing alias for "abcd". You should use: "abc"
$ alias abc=abcd ab=abcd a=abcd
$ abcd
Found existing alias for "abcd". You should use: "a"

The first one should be "ab"

spotlesscoder commented 3 years ago

Also for me an issue

In my .zshrc I have

alias cd..="cd .."
alias ..="cd .."

Result:

user@pc  ~  cd ..       
Found existing alias for "cd ..". You should use: "cd.."
user@pc  /home  

I would have expected the suggestion of using the shorter .. alias

Arcitec commented 2 years ago

https://github.com/djui/alias-tips is a bad solution. It literally boots up a Python interpreter every time you run a shell command, lol. It's terrible!

zsh-you-should-use is much better, because it's just a fast, minimalistic, pure zsh script.

But perhaps some of its algorithms can be ported to Zsh, because alias-tips is good at finding the shortest matching alias.

MichaelAquilina commented 2 years ago

Writing in python is lot easier than writing zsh scripts I says this with python as my main daily language :)

Some of those algorithms might require quite a bit of work as a result. But I'd be happy for someone to try give it a go. Alternatively you can also wait for me to have the time to do it, but I cant make any promises in terms of when

Arcitec commented 2 years ago

@MichaelAquilina Totally understandable. Actually, I am very happy with your plugin now, when I discovered export YSU_MODE=ALL which lets me see every alias! :) It's enough for me because it prints every matching alias, instead of attempting to pick some arbitrary "best match". :)

olets commented 8 months ago

This might be helpful https://unix.stackexchange.com/a/482492