zsh-autosuggestions

repository·master·Indexed 12 days ago

https://github.com/zsh-users/zsh-autosuggestions

A Zsh plugin providing Fish-shell-like fast and unobtrusive autosuggestions based on command history and the completion engine. Requires Zsh v4.3.11 or later. Features include configurable suggestion strategies (history, completion, match_prev_cmd), asynchronous mode for Zsh 5.0.8+, and customizable highlight styles via ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE.

Tokens
2.5K
Snippets
10
Records
17
Agent score
49%

What's inside zsh-autosuggestions

  1. Install zsh-autosuggestions manually via Git Clone

    master
    1. Clone the repository to a directory of your choice (e.g., ~/.zsh/zsh-autosuggestions):
      git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
    2. Source the plugin in your .zshrc file:
      source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
    3. Start a new terminal session.
    git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions
    
    # Add to ~/.zshrc
    source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh
  2. Install zsh-autosuggestions via Homebrew

    master
    1. Install the package using Homebrew:
      brew install zsh-autosuggestions
    2. Activate the plugin by adding the following line to the end of your .zshrc file:
      source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
    3. Start a new terminal session.
    brew install zsh-autosuggestions
    
    # Add to ~/.zshrc
    source $(brew --prefix)/share/zsh-autosuggestions/zsh-autosuggestions.zsh
  3. Install zsh-autosuggestions with Oh My Zsh

    master

    To use this plugin with Oh My Zsh, follow these steps:

    1. Clone the repository into your Oh My Zsh custom plugins directory (usually ~/.oh-my-zsh/custom/plugins):
      git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    2. Add zsh-autosuggestions to your plugins array in your .zshrc file.
    3. Start a new terminal session.
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    
    # In ~/.zshrc
    plugins=(
        # other plugins...
        zsh-autosuggestions
    )
  4. How to use zsh-autosuggestions

    master

    As you type commands, suggestions appear after the cursor in a muted color.

    • Accept full suggestion: Press the <kbd>→</kbd> key (forward-char widget) or <kbd>End</kbd> (end-of-line widget) when the cursor is at the end of the buffer.
    • Partially accept suggestion: Invoke the forward-word widget to accept the suggestion up to the point where the cursor moves.
  5. Disable automatic widget re-binding for performance

    master

    By default, the plugin re-binds widgets on every precmd. To disable this and boost performance, set ZSH_AUTOSUGGEST_MANUAL_REBIND to any value.

    Warning: If you do this, you must manually call _zsh_autosuggest_bind_widgets if you change widget lists or if other plugins wrap autosuggest widgets.

  6. Configure suggestion strategies

    master

    The ZSH_AUTOSUGGEST_STRATEGY array defines the order in which suggestion engines are tried. The plugin uses the first strategy that returns a match.

    Available strategies:

    • history: Most recent match from command history.
    • completion: Suggestion based on tab-completion (requires zpty module).
    • match_prev_cmd: Most recent match whose preceding history item matches the most recently executed command.
    ZSH_AUTOSUGGEST_STRATEGY=(history completion)
  7. Configure Asynchronous Mode

    master

    Suggestions are fetched asynchronously by default in Zsh 5.0.8+.

    • To disable async (use synchronous mode): unset ZSH_AUTOSUGGEST_USE_ASYNC after sourcing the plugin.
    • To enable async on older Zsh (< 5.0.8): Set ZSH_AUTOSUGGEST_USE_ASYNC to any value after sourcing the plugin.
  8. Map ZLE widgets to plugin behaviors

    master

    You can control how the plugin interacts with Zsh Line Editor (ZLE) widgets by adding or removing them from these arrays:

    • ZSH_AUTOSUGGEST_CLEAR_WIDGETS: Clears the suggestion.
    • ZSH_AUTOSUGGEST_ACCEPT_WIDGETS: Accepts the suggestion.
    • ZSH_AUTOSUGGEST_EXECUTE_WIDGETS: Executes the suggestion.
    • ZSH_AUTOSUGGEST_PARTIAL_ACCEPT_WIDGETS: Partially accepts the suggestion.
    • ZSH_AUTOSUGGEST_IGNORE_WIDGETS: Prevents the plugin from triggering any behavior.
  9. Ignore history suggestions matching a pattern

    master

    Use ZSH_AUTOSUGGEST_HISTORY with a glob pattern to prevent the history and match_prev_cmd strategies from suggesting specific commands.

    # Never suggest 'cd' commands
    ZSH_AUTOSUGGEST_HISTORY="cd *"
    
    # Never suggest anything 50 characters or longer
    ZSH_AUTOSUGGEST_HISTORY="?(#c50,)"