autoload -U +X compinit && compinit autoload -U +X bashcompinit && bashcompinit source /path/to/your/bash_completion_script
I am running zsh zsh 5.0.2 (x86_64-apple-darwin13.0) without any ~ / .zshrc , and the above sequence works in the newly created zsh shell.
Thanks to git -completion.bash script for a hint: D
For more details on the three lines:
Bash has awesome built-in autocomplete support, but autocomplete bash scripts do not work directly with zsh, since the zsh environment does not have the necessary auxiliary helper functions of bash, such as compgen , complete . He does this to speed up the zsh session.
These days, zsh comes with matching completion scripts like compinit and bashcompinit , which have the necessary functions to support autocomplete bash scripts.
autoload <func_name> : Note that autoload is defined in zsh, not bash. autoload searches for the file named in the directory path returned by the fpath command and marks the function that loads it the first time it is called.
- -U: Ignore any aliases when loading a function such as compinit or bashcompinit
- + X: Just load the named function now and don't execute it
For example, on my system, echo $fpath returns /usr/share/zsh/site-functions and /usr/share/zsh/5.0.5/functions , and both compinit and bashcompinit are available in /usr/share/zsh/5.0.5/functions .
Also for most people there can only be autoload -U +X bashcompinit && bashcompinit , because some other script like git autocomplete or their own ~/.zshrc can execute autoload -U +X compinit && compinit , but it's safe to just run both of them.
Jatin Kumar Jan 09 '15 at 4:44 2015-01-09 04:44
source share