Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Offer zsh-autosuggestion as a completion candidate
# Make the autosuggestion a completion value
function _autosuggest_complete() {
local -a candidates
# IMPROVEMENT: If we can be sure that autosuggest has already run we can
# just grab the suggestion variable, avoiding the double call
local orignal_ZSH_AUTOSUGGEST_USE_ASYNC=$ZSH_AUTOSUGGEST_USE_ASYNC
ZSH_AUTOSUGGEST_USE_ASYNC=0 # need the result immediately
_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY "$BUFFER"
ZSH_AUTOSUGGEST_USE_ASYNC=$orignal_ZSH_AUTOSUGGEST_USE_ASYNC
# Escape ':' since it has special meaning to _describe
candidates=( ${${suggestion[$((CURSOR-$#PREFIX+1)),-1]}//:\\:} )
_describe -t auto-suggestion auto-suggestion candidates -Q
}
# Functions marked with '-first-' is called first by the '_complete' completer
compdef _autosuggest_complete -first-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment