I have a Bash tab-completion script for Apache's Hadoop. Normally, I use zsh as my day-to-day shell. It tends to be pretty bash-like when I need it to be, but it looks like the tab-completion systems are radically different between them. Is there a simple way to "convert" the existing bash-tab-completion definitions to work in zsh? I don't want to invest a ton of time in this, but if it's easy I'd save a moderate amount of effort.
相关问题
- JQ: Select when attribute value exists in a bash a
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
- UNIX Bash - Removing double quotes from specific s
相关文章
- Check if directory exists on remote machine with s
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- How can I create a “tmp” directory with Elastic Be
- Spread 'sed' command over multiple lines
From this page (dated 2010/01/05):
I am running zsh
zsh 5.0.2 (x86_64-apple-darwin13.0)
without any ~/.zshrc and the above sequence worked in a freshly spawned zsh shell.Thanks to git-completion.bash script for the hint :D
Read-on for more details on above 3 lines:
Bash has awesome in built auto completion support but the bash autocomplete scripts don't work directly zsh as zsh environment doesn't have the essential bash autocomplete helper functions like
compgen
,complete
. It does so in an effort to keep zsh session fast.These days zsh is shipped with appropriate completion scripts like
compinit
andbashcompinit
which have the required functions to support bash autocomplete scripts.autoload <func_name>
: Note that autoload is defined in zsh and not bash.autoload
looks for a file named in the directory paths returned byfpath
command and marks a function to load the same when it is first invoked.For example on my system
echo $fpath
returns/usr/share/zsh/site-functions
and/usr/share/zsh/5.0.5/functions
and bothcompinit
andbashcompinit
are available at/usr/share/zsh/5.0.5/functions
.Also for most people may be only
autoload -U +X bashcompinit && bashcompinit
is required because some other script like git autocomplete or their own~/.zshrc
may be doingautoload -U +X compinit && compinit
, but it's safe to just run both of them.I am running Antigen as a Oh-My-Zsh plugin manager. I had a few bash completion scripts written by coworkers that I wanted to load into Zsh with a simple
source /path/to/completion
.I had some trouble, because it seems like either Antigen or OMZ (hard to tell) concern themselves with only loading completion scripts from their plugins. I finally got around this by autoloading
bashcompinit
andcompinit
afterantigen apply
. Simply autoloadingbashcompinit
wasn't enough.Antigen creates its
.zcompdump
file at$ANTIGEN_COMPDUMP
which for me was~/.antigen/.zcompdump
The re-invoke of compinit and bashcompinit create a second .zcompdump at
$HOME/.zcompdump
That seems to all work out, because I am able to use the completions set up by
/path/to/bash_completion
. I've deleted both .zcompdump files a few times to make sure they're regenerated and seems to work.I've had to rm the .zcompdump files a few times after a machine reboot because of errors thrown when trying to tab complete, but I'm unsure if that's due to this set up or something else.
rm ~/.zcompdump && rm $ANTIGEN_COMPDUMP
and a new shell fixes that for me.Versions used at time of writing:
For
zsh
use:compdef
compadd
My example:
Source: My code https://github.com/reduardo7/bashx