Convert Figma logo to code with AI

zsh-users logozsh-autosuggestions

Fish-like autosuggestions for zsh

30,920
1,855
30,920
169

Top Related Projects

172,325

🙃 A delightful community-driven (with 2,300+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.

13,946

The configuration framework for Zsh

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.

Feature-rich syntax highlighting for ZSH

A Zsh theme

Fish shell like syntax highlighting for Zsh.

Quick Overview

Zsh-autosuggestions is a plugin for Zsh that suggests commands as you type based on your command history and completions. It provides fish-like autosuggestions for Zsh, enhancing the shell experience by offering intelligent command predictions.

Pros

  • Improves productivity by reducing typing and recalling commands
  • Seamless integration with Zsh and other popular plugins
  • Customizable behavior and appearance
  • Lightweight and fast, with minimal impact on shell performance

Cons

  • May occasionally suggest unwanted or irrelevant commands
  • Can be distracting for some users, especially when learning new commands
  • Requires some initial setup and configuration
  • May conflict with other Zsh plugins or custom configurations

Getting Started

  1. Clone the repository into your Zsh plugins directory:

    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    
  2. Add the plugin to your .zshrc file:

    plugins=(... zsh-autosuggestions)
    
  3. Restart your Zsh session or run:

    source ~/.zshrc
    
  4. (Optional) Customize the plugin by adding settings to your .zshrc:

    ZSH_AUTOSUGGEST_STRATEGY=(history completion)
    ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#999999"
    

Competitor Comparisons

172,325

🙃 A delightful community-driven (with 2,300+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool that makes it easy to keep up with the latest updates from the community.

Pros of Oh My Zsh

  • Comprehensive framework with a wide range of plugins and themes
  • Active community with frequent updates and contributions
  • Easy to set up and configure for beginners

Cons of Oh My Zsh

  • Can be slower to load due to its extensive feature set
  • May include unnecessary features for some users
  • Potential for conflicts between plugins or themes

Code Comparison

Oh My Zsh (example theme configuration):

ZSH_THEME="robbyrussell"
plugins=(git docker kubectl)
source $ZSH/oh-my-zsh.sh

zsh-autosuggestions (installation and usage):

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

Summary

Oh My Zsh is a full-featured Zsh framework offering a wide range of plugins and themes, making it ideal for users who want a comprehensive solution. However, it may be overkill for those seeking specific functionality. zsh-autosuggestions, on the other hand, focuses solely on providing autosuggestions, making it lightweight and easy to integrate into existing Zsh setups. Users should consider their needs and preferences when choosing between these options.

13,946

The configuration framework for Zsh

Pros of Prezto

  • Comprehensive ZSH configuration framework with modular design
  • Includes a wide range of pre-configured modules for enhanced functionality
  • Offers themes and prompts for customizable shell appearance

Cons of Prezto

  • Steeper learning curve due to its extensive features and configuration options
  • Potentially slower shell startup time compared to minimal configurations

Code Comparison

Prezto configuration (.zpreztorc):

zstyle ':prezto:*:*' color 'yes'
zstyle ':prezto:load' pmodule \
  'environment' \
  'terminal' \
  'editor' \
  'history' \
  'directory' \
  'spectrum' \
  'utility' \
  'completion' \
  'prompt'

zsh-autosuggestions configuration (.zshrc):

source /path/to/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20

Prezto provides a more comprehensive ZSH configuration framework with modular design and pre-configured modules, while zsh-autosuggestions focuses specifically on providing autosuggestions based on command history and completions. Prezto offers more customization options but may have a steeper learning curve, whereas zsh-autosuggestions is simpler to set up and use but has a more focused feature set.

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.

Pros of zsh-autocomplete

  • More comprehensive autocomplete functionality, including menu selection and inline suggestions
  • Offers fuzzy matching for more flexible command completion
  • Provides real-time, as-you-type completions for a more interactive experience

Cons of zsh-autocomplete

  • Can be slower and more resource-intensive, especially on older hardware
  • May have a steeper learning curve due to its more complex features
  • Might conflict with other Zsh plugins or custom configurations

Code Comparison

zsh-autosuggestions:

source /path/to/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'

zsh-autocomplete:

source /path/to/zsh-autocomplete.plugin.zsh
zstyle ':autocomplete:*' min-input 2
zstyle ':autocomplete:*' widget-style menu-select

Both plugins aim to enhance the Zsh command-line experience, but they take different approaches. zsh-autosuggestions focuses on providing simple, history-based suggestions, while zsh-autocomplete offers a more comprehensive and interactive autocomplete system. The choice between them depends on personal preference, system resources, and desired functionality.

Feature-rich syntax highlighting for ZSH

Pros of fast-syntax-highlighting

  • Offers more advanced and comprehensive syntax highlighting
  • Provides real-time highlighting as you type
  • Supports a wider range of file types and languages

Cons of fast-syntax-highlighting

  • May have a slightly higher performance impact on system resources
  • Requires more configuration to fully customize
  • Can be overwhelming for users who prefer simpler setups

Code comparison

fast-syntax-highlighting:

# Enable the plugin
zinit light zdharma-continuum/fast-syntax-highlighting

# Customize highlighting styles
FAST_HIGHLIGHT_STYLES[alias]='fg=blue,bold'
FAST_HIGHLIGHT_STYLES[command]='fg=green,bold'

zsh-autosuggestions:

# Enable the plugin
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

# Customize suggestion style
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'

Summary

fast-syntax-highlighting offers more advanced and comprehensive syntax highlighting, supporting a wider range of file types and languages. It provides real-time highlighting as you type, which can enhance the overall shell experience. However, it may have a slightly higher performance impact and requires more configuration to fully customize. On the other hand, zsh-autosuggestions focuses specifically on providing autosuggestions based on command history, which can be simpler to set up and use for those who prioritize command completion over extensive syntax highlighting.

A Zsh theme

Pros of powerlevel10k

  • Highly customizable prompt with many built-in themes and options
  • Fast performance, even with complex configurations
  • Seamless integration with version control systems and command-line tools

Cons of powerlevel10k

  • Steeper learning curve due to numerous configuration options
  • May require additional fonts or icons for full functionality
  • Focuses on prompt appearance rather than command-line suggestions

Code comparison

zsh-autosuggestions:

source /path/to/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'

powerlevel10k:

source /path/to/powerlevel10k.zsh-theme
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir vcs)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs time)

zsh-autosuggestions provides inline suggestions based on command history, enhancing productivity by reducing typing. powerlevel10k, on the other hand, focuses on creating a visually appealing and informative prompt with customizable segments. While zsh-autosuggestions is simpler to set up and use, powerlevel10k offers more extensive customization options for users who want a highly tailored shell experience. The choice between the two depends on whether you prioritize command suggestions or prompt aesthetics and information display.

Fish shell like syntax highlighting for Zsh.

Pros of zsh-syntax-highlighting

  • Provides real-time syntax highlighting for commands as you type
  • Highlights errors and invalid commands before execution
  • Supports custom highlighting rules for specific commands or patterns

Cons of zsh-syntax-highlighting

  • May slightly increase command-line latency on slower systems
  • Requires manual configuration for optimal highlighting rules
  • Can be visually distracting for some users

Code comparison

zsh-syntax-highlighting:

ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
ZSH_HIGHLIGHT_STYLES[command]='fg=blue,bold'
ZSH_HIGHLIGHT_STYLES[alias]='fg=magenta,bold'

zsh-autosuggestions:

ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
bindkey '^ ' autosuggest-accept

zsh-syntax-highlighting focuses on colorizing command-line input in real-time, while zsh-autosuggestions provides inline suggestions based on command history and completion. Both plugins enhance the Zsh experience but serve different purposes. zsh-syntax-highlighting improves readability and error detection, while zsh-autosuggestions speeds up command entry by offering contextual suggestions.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

zsh-autosuggestions

Fish-like fast/unobtrusive autosuggestions for zsh.

It suggests commands as you type based on history and completions.

Requirements: Zsh v4.3.11 or later

CircleCI Chat on Gitter

Installation

See INSTALL.md.

Usage

As you type commands, you will see a completion offered after the cursor in a muted gray color. This color can be changed by setting the ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE variable. See configuration.

If you press the → key (forward-char widget) or End (end-of-line widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.

If you invoke the forward-word widget, it will partially accept the suggestion up to the point that the cursor moves to.

Configuration

You may want to override the default global config variables. Default values of these variables can be found here.

Note: If you are using Oh My Zsh, you can put this configuration in a file in the $ZSH_CUSTOM directory. See their comments on overriding internals.

Suggestion Highlight Style

Set ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE to configure the style that the suggestion is shown with. The default is fg=8, which will set the foreground color to color 8 from the 256-color palette. If your terminal only supports 8 colors, you will need to use a number between 0 and 7.

Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"

For more info, read the Character Highlighting section of the zsh manual: man zshzle or online.

Note: Some iTerm2 users have reported not being able to see the suggestions. If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are different.

Suggestion Strategy

ZSH_AUTOSUGGEST_STRATEGY is an array that specifies how suggestions should be generated. The strategies in the array are tried successively until a suggestion is found. There are currently three built-in strategies to choose from:

  • history: Chooses the most recent match from history.
  • completion: Chooses a suggestion based on what tab-completion would suggest. (requires zpty module, which is included with zsh since 4.0.1)
  • match_prev_cmd: Like history, but chooses the most recent match whose preceding history item matches the most recently executed command (more info). Note that this strategy won't work as expected with ZSH options that don't preserve the history order such as HIST_IGNORE_ALL_DUPS or HIST_EXPIRE_DUPS_FIRST.

For example, setting ZSH_AUTOSUGGEST_STRATEGY=(history completion) will first try to find a suggestion from your history, but, if it can't find a match, will find a suggestion from the completion engine.

Widget Mapping

This plugin works by triggering custom behavior when certain zle widgets are invoked. You can add and remove widgets from these arrays to change the behavior of this plugin:

  • ZSH_AUTOSUGGEST_CLEAR_WIDGETS: Widgets in this array will clear the suggestion when invoked.
  • ZSH_AUTOSUGGEST_ACCEPT_WIDGETS: Widgets in this array will accept the suggestion when invoked.
  • ZSH_AUTOSUGGEST_EXECUTE_WIDGETS: Widgets in this array will execute the suggestion when invoked.
  • ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS: Widgets in this array will partially accept the suggestion when invoked.
  • ZSH_AUTOSUGGEST_IGNORE_WIDGETS: Widgets in this array will not trigger any custom behavior.

Widgets that modify the buffer and are not found in any of these arrays will fetch a new suggestion after they are invoked.

Note: A widget shouldn't belong to more than one of the above arrays.

Disabling suggestion for large buffers

Set ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE to an integer value to disable autosuggestion for large buffers. The default is unset, which means that autosuggestion will be tried for any buffer size. Recommended value is 20. This can be useful when pasting large amount of text in the terminal, to avoid triggering autosuggestion for strings that are too long.

Asynchronous Mode

Suggestions are fetched asynchronously by default in zsh versions 5.0.8 and greater. To disable asynchronous suggestions and fetch them synchronously instead, unset ZSH_AUTOSUGGEST_USE_ASYNC after sourcing the plugin.

Alternatively, if you are using a version of zsh older than 5.0.8 and want to enable asynchronous mode, set the ZSH_AUTOSUGGEST_USE_ASYNC variable after sourcing the plugin (it can be set to anything). Note that there is a bug in versions of zsh older than 5.0.8 where ctrl + c will fail to reset the prompt immediately after fetching a suggestion asynchronously.

Disabling automatic widget re-binding

Set ZSH_AUTOSUGGEST_MANUAL_REBIND (it can be set to anything) to disable automatic widget re-binding on each precmd. This can be a big boost to performance, but you'll need to handle re-binding yourself if any of the widget lists change or if you or another plugin wrap any of the autosuggest widgets. To re-bind widgets, run _zsh_autosuggest_bind_widgets.

Ignoring history suggestions that match a pattern

Set ZSH_AUTOSUGGEST_HISTORY_IGNORE to a glob pattern to prevent offering suggestions for history entries that match the pattern. For example, set it to "cd *" to never suggest any cd commands from history. Or set to "?(#c50,)" to never suggest anything 50 characters or longer.

Note: This only affects the history and match_prev_cmd suggestion strategies.

Skipping completion suggestions for certain cases

Set ZSH_AUTOSUGGEST_COMPLETION_IGNORE to a glob pattern to prevent offering completion suggestions when the buffer matches that pattern. For example, set it to "git *" to disable completion suggestions for git subcommands.

Note: This only affects the completion suggestion strategy.

Key Bindings

This plugin provides a few widgets that you can use with bindkey:

  1. autosuggest-accept: Accepts the current suggestion.
  2. autosuggest-execute: Accepts and executes the current suggestion.
  3. autosuggest-clear: Clears the current suggestion.
  4. autosuggest-fetch: Fetches a suggestion (works even when suggestions are disabled).
  5. autosuggest-disable: Disables suggestions.
  6. autosuggest-enable: Re-enables suggestions.
  7. autosuggest-toggle: Toggles between enabled/disabled suggestions.

For example, this would bind ctrl + space to accept the current suggestion.

bindkey '^ ' autosuggest-accept

Troubleshooting

If you have a problem, please search through the list of issues on GitHub to see if someone else has already reported it.

Reporting an Issue

Before reporting an issue, please try temporarily disabling sections of your configuration and other plugins that may be conflicting with this plugin to isolate the problem.

When reporting an issue, please include:

  • The smallest, simplest .zshrc configuration that will reproduce the problem. See this comment for a good example of what this means.
  • The version of zsh you're using (zsh --version)
  • Which operating system you're running

Uninstallation

  1. Remove the code referencing this plugin from ~/.zshrc.

  2. Remove the git repository from your hard drive

    rm -rf ~/.zsh/zsh-autosuggestions # Or wherever you installed
    

Development

Build Process

Edit the source files in src/. Run make to build zsh-autosuggestions.zsh from those source files.

Pull Requests

Pull requests are welcome! If you send a pull request, please:

  • Request to merge into the develop branch (NOT master)
  • Match the existing coding conventions.
  • Include helpful comments to keep the barrier-to-entry low for people new to the project.
  • Write tests that cover your code as much as possible.

Testing

Tests are written in ruby using the rspec framework. They use tmux to drive a pseudoterminal, sending simulated keystrokes and making assertions on the terminal content.

Test files live in spec/. To run the tests, run make test. To run a specific test, run TESTS=spec/some_spec.rb make test. You can also specify a zsh binary to use by setting the TEST_ZSH_BIN environment variable (ex: TEST_ZSH_BIN=/bin/zsh make test).

A docker image for testing is available on docker hub. It comes with ruby, the bundler dependencies, and all supported versions of zsh installed.

Pull the docker image with:

docker pull ericfreese/zsh-autosuggestions-test

To run the tests for a specific version of zsh (where <version> below is substituted with the contents of a line from the ZSH_VERSIONS file):

docker run -it -e TEST_ZSH_BIN=zsh-<version> -v $PWD:/zsh-autosuggestions zsh-autosuggestions-test make test

License

This project is licensed under MIT license. For the full text of the license, see the LICENSE file.