Reputation: 94
I am using zsh.
I have a command foo
, and I use alias foo="sudo foo"
as a shortcut. I want zsh to complete the command just like I typed foo
.
I googled and found compdef _foo f=foo
which can deal with it. When I type f something<tab>
, the completion works fine. But when I try compdef _foo foo=foo
and then foo something<tab>
, it does not work.
Is there a way to deal with the Tab completion when I use an alias with the same name as the original command?
Upvotes: 0
Views: 1110
Reputation: 94
The problem is actually a special case happened to me.
As @blueray said, zsh is able to complete commands like sudo foo
or an alias of it normally.
Thanks to @rcwnd_cz , I found that adding setopt complete_aliases
solves my problem. The point is that I set an alias somewhere else that maps sudo
to sudo FOO=bar
. As a result, alias foo="sudo foo"
is an "alias in alias", and zsh refuses to complete it. Setting setopt complete_aliases
solves it perfectly.
Upvotes: 2