zsh-you-should-use icon indicating copy to clipboard operation
zsh-you-should-use copied to clipboard

Some shorter aliases are not detected

Open benwaffle opened this issue 5 years ago • 13 comments

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?

  • [ ] zplug
  • [ ] oh-my-zsh
  • [x] Antigen
  • [ ] Other (please specify)

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.

benwaffle avatar Aug 06 '19 01:08 benwaffle

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 avatar Aug 21 '19 17:08 MichaelAquilina

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

MichaelAquilina avatar Oct 07 '19 11:10 MichaelAquilina

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

MichaelAquilina avatar Oct 12 '19 23:10 MichaelAquilina

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

MichaelAquilina avatar Oct 14 '19 22:10 MichaelAquilina

Emmm, why the fix was reverted?

Aloxaf avatar Dec 25 '19 06:12 Aloxaf

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.

MichaelAquilina avatar Dec 28 '19 19:12 MichaelAquilina

@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'}"
}

NightMachinery avatar Apr 06 '20 22:04 NightMachinery

@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"

MDHD-Yee avatar Jun 18 '20 20:06 MDHD-Yee

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

spotlesscoder avatar Jan 03 '21 08:01 spotlesscoder

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.

Arcitec avatar Dec 16 '21 17:12 Arcitec

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

MichaelAquilina avatar Dec 16 '21 17:12 MichaelAquilina

@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". :)

Arcitec avatar Dec 16 '21 17:12 Arcitec

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

olets avatar Oct 23 '23 02:10 olets