Consider support function aliases
Dentrax opened this issue · 5 comments
Issue Details
Right now, you-should-use
only recognizes aliases if command given well: alias gs='git status
. But this not works for function aliases. It should better if it recognize this type of aliases: alias my_alias='my_custom_function [COMMANDS] [FLAGS] [OPTIONS]
Operating System (uname -a)
Darwin XXX 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64
zsh version (zsh --version)
zsh 5.8 (x86_64-apple-darwin20.1.0)
you-should-use version (echo "$YSU_VERSION")
1.7.3
How is zsh-you-should-use installed?
- zplug
- oh-my-zsh
- Antigen
- Other (please specify)
Steps to reproduce the issue
- Create a
function.zsh
file - Create an alias function:
_my_git() {
# my some other special stuffs here
git "$@"
}
- Define an
alias
to that function in youraliases.zsh
file:
alias gs='_my_git status --short --branch --show-stash'
- Source the
.zsh
files in your.zshrc
file $ git status
Actual:
Found existing alias for "git status". You should use: "gst"
Found existing git alias for "status". You should use: "git st"
Expected:
Found existing alias for "git status". You should use: "gs"
Found existing alias for "git status". You should use: "gst"
Found existing git alias for "status". You should use: "git st"
I'm not actually sure I understand the problem here. Step 5 does not mention the function in any way so I wouldnt expect one of its aliases to be suggested. Is this a mistake in the issue description or am I just misunderstanding the problem?
Actually the issue steps are correct. In case we call gs
, we do not mention the git
command directly but indirectly in the _my_git()
function. That's because _my_git()
takes an "$@"
for git
command, which means we are passing whole args to git
indirectly. In case you ask what happens in these similar cases:
_my_awesome_func() {
git "$@"
echo -n "$1"
foo "$@"
}
$ alias call_me='_my_awesome_func() status'
$ git status
Found existing alias for "git status". You should use: "call_me"
$ foo status
Found existing alias for "foo status". You should use: "call_me"
$ echo -n "Hello"
Found existing alias for "echo -n". You should use: "call_me"
But this case, there may occur some consistency problems. When I call echo -n "Hello"
I really meant to call call_me
instead? Actually no, I was created this function only for git
use-case purposes. 🤔
I'm afraid introspecting a function that way is extremely difficult to do efficiently and accurately. Even for your relatively simple function example its not even obvious that it should be suggested as an alternative as its behaviour is inherently different to git status
. For these reasons I'd say that unfortunately the answer to whether this feature could be implementation would be a no :/
I think you're right; that's what I thought when I wrote my last comment. :) What I understand is that we should not use functions in aliases to use this plugin properly.
Thanks for confirming @Dentrax :) going to be closing this issue. Let me know if you think otherwise!