Home

Awesome

zsh-bash-completions-fallback

This plugin is intended to use the bash completions when a zsh completion is not available.

While this could be supported natively via bashcompinit, this doesn't actually work most of the times, as completion scripts may use syntax not supported by zsh, and so it's just better to implement this querying the bash itself, using a bash script called at completion time (based on Brian Baffa implementation and including various fixes to support commands and completion parameters).

Make sure you load this after other plugins to prevent their completions to be replaced by the (simpler) bash ones.

Most of all bash completions can now work as they precisely do in bash, as per the compopt simulation that is added here. It may be used to control the output or avoid adding spaces or limit the results.

The plugin by default works by lazy-loading the completions the first time you hit TAB to complete a command, however this can be controlled using the $ZSH_BASH_COMPLETIONS_FALLBACK_LAZYLOAD_DISABLE parameter, to load them all on startup.

If a new bash completion has been installed in the system, you can just restart zsh or call _bash_completions_load, if instead you want this to be handled automatically, you can use $ZSH_BASH_COMPLETIONS_FALLBACK_LAZYLOAD_AUTO_UPDATE to update all the the available completions at every TAB-completion. This is disabled by default, to avoid IO operations at each completion, but it is still very fast in most of the platforms.

Once loaded you can see all the completions available via bash (through this script) using:

_bash_completions_fallback_list_handled_completions

Requirements

Install

Using Oh-my-zsh:

  1. Clone this repository in oh-my-zsh's plugins directory:

     git clone https://github.com/3v1n0/zsh-bash-completions-fallback ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-bash-completions-fallback
    
  2. Activate the plugin in ~/.zshrc (make sure it's set as the last one not to replace completions provided by other plugins):

     plugins=( [plugins...] zsh-bash-completions-fallback)
    
  3. Source ~/.zshrc (or restart zsh) to take changes into account

     source ~/.zshrc
    

Using Zinit:

Using other plugins manager:

    # Depending on the tool the syntax may vary but it's generally just
    $your_plugin_manager 3v1n0/zsh-bash-completions-fallback

Manual installation:

  1. Clone this repository in a folder (like ~/.zsh-bash-completions-fallback):

     git clone https://github.com/3v1n0/zsh-bash-completions-fallback $HOME/.zsh-bash-completions-fallback
    
  2. Add to your ~/.zshrc:

     source $HOME/.zsh-bash-completions-fallback/zsh-bash-completions-fallback.plugin.zsh
    
  3. Source ~/.zshrc (or restart zsh) to start using the plugin

     # This plugin requires compinit, so make sure that your ~/.zshrc or
     # your package manager loads it before, otherwise this is needed
     #autoload -U compinit && compinit
     source ~/.zshrc
    
  4. Of course in case you want to test it temporary you just have to source the plugin file (zsh-bash-completions-fallback.plugin.zsh)

Configuration

This script defines the following global variables. You may override their default values only after having loaded this script into your ZSH session.