iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💨

IDE-like Auto-completion in zsh: Introduction to zsh-autocomplete

に公開

Have you ever wished for incremental auto-completion in your shell, just like in an IDE, without having to press Tab?
For those of you who find yourselves naturally typing Tab about once every five times, I have good news.

By using this zsh-autocomplete, you can finally be liberated from unnecessary Tab typing 🎉
https://github.com/marlonrichert/zsh-autocomplete

file-search

Differences from Previous Methods

Actually, zsh plugins that provide auto-completion candidates have existed for a long time.
They are [incr-0.2.zsh](https://mimosa-pudica.net/zsh-incremental.html and
https://github.com/hchbaw/auto-fu.zsh
(for some reason, both are by Japanese authors).

However, both of these plugins are old, and development has stopped. (The last update was in 2013.)

Another commonly used similar tool is
https://github.com/zsh-users/zsh-autosuggestions
While this one provides auto-completion, it displays only a single suggestion rather than the full list of candidates.

That is where zsh-autocomplete appeared on the scene in 2020.

Advantages of zsh-autocomplete

  • You don't have to press Tab.
  • Since items are always displayed, you know exactly when you actually need to press Tab.
  • It processes asynchronously, so it doesn't interfere much with your input.
  • it intelligently truncates results when there are many candidates.
  • People who are tired of pressing Tab.
  • People who like rich screens that dynamically display a lot of information.

Who might want to avoid it:

  • People who have customized various completion settings and try to do the same with zsh-autocomplete.
    • Completion customizations often lead to issues, so it is better to only modify within the scope of the official settings.
  • People who like changing the appearance or restricting unnecessary features.
    • It is more of a "follow the author's settings" type of plugin (since these processes have many side effects, improper tweaking often causes things to break during updates).
  • People who use many zsh plugins but don't want to spend much time on maintenance.
    • Due to strong side effects, it's necessary to carefully adjust the loading order with other plugins.

Precautions for Configuration

Parameters are divided into those set before loading the plugin and those set after. The split point is here.
Make sure not to get the timing wrong when applying various settings.

If you are using zinit, you should control this using atinit and atload.

Other Methods

Some terminals include completion features as a built-in capability.
https://github.com/Inlustra/hyper-autocomplete
https://github.com/withfig/fig

Using a slightly different approach, some tools display a custom prompt after running a command, allowing for auto-completion popups within that prompt (though this is limited to git).
https://github.com/chriswalz/bit

Personal Thoughts

Personally, I feel that auto-completion is essential everywhere, so I'm hoping for a future where the shell and terminal handle it seamlessly, rather than relying on plugins...

I want a shell like this:

  • Rich display by default (e.g., git prompt, colors)
  • IDE-like completion
  • FuzzyFinder-like filtering in various places
  • Ability to install packages from GitHub
  • Shell scripting in a proper language
  • Easy-to-write completion definitions
  • Easy to hook into various events

Discussion