Skip to content

Instantly share code, notes, and snippets.

@olejorgenb
Created September 3, 2017 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olejorgenb/678ddc534c157ffb7c61151cf8eb8d03 to your computer and use it in GitHub Desktop.
Save olejorgenb/678ddc534c157ffb7c61151cf8eb8d03 to your computer and use it in GitHub Desktop.
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