Add a widget to accept and execute the current suggestion. #125

Merged
merged 3 commits into from Mar 5, 2016

2 participants

@ericfreese
zsh-users member

This adds a new widget, autosuggest-execute, that accepts and executes the current suggestion.

It is not triggered by any widgets by default. ZSH_AUTOSUGGEST_EXECUTE_WIDGETS is empty by default, but widgets can be added to that array after sourcing the plugin or the widget can be used with bindkey.

Two ways of using it:

  • You can add widgets to ZSH_AUTOSUGGEST_EXECUTE_WIDGETS. For example, this will accept and execute the suggestion when the accept-line widget is triggered (usually when you press enter).

    # Remove accept-line from CLEAR list
    ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#accept-line}")
    
    # Add accept-line to EXECUTE list
    ZSH_AUTOSUGGEST_EXECUTE_WIDGETS+=(accept-line)
  • You can bind a keypress to it using bindkey. For example, this will accept and execute the suggestion when you press enter:

    bindkey '^M' autosuggest-execute
    

cc @hitripod

@ericfreese ericfreese merged commit 9df362f into v0.3.x Mar 5, 2016
@ericfreese ericfreese deleted the features/execute_widget branch Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment