Zsh completion on the second command or after an alias

autocompletezsh

I have changed my OS X Yosemite shell to Zsh and configured with "oh my zsh" plugins, recently i installed proxychains-ng to proxy command line tools, but i found zsh completion does not work on the command after proxychains4, like

proxychains4 wget [hit tab], will not come up with wget's options
proxychains4 gi[tab], will not come up with "git"

And zsh does not work on command after alias either,

alias proxy="http_proxy=http://127.0.0.1:12345"
proxy brew[hit tab], will not come up with brew's subcommands

there will be no completions for command and it's option. Any idea? thank you.

Best Answer

By default, zsh expands alias before doing completion. It's possible that your configuration disables this; you can reenable it explicitly by unsetting the complete_aliases option.

unsetopt complete_aliases

For an external command like proxychains4, you can declare that its arguments are themselves a command and its arguments by making its completion _precommand. This isn't easy to find in the documentation, but you can observe the configuration for similar commands such as nohup by running echo $_comps[nohup]. This is with the “new” completion system (after running compinit).

compdef _precommand proxychains4