Created
September 3, 2017 02:13
-
-
Save olejorgenb/678ddc534c157ffb7c61151cf8eb8d03 to your computer and use it in GitHub Desktop.
Offer zsh-autosuggestion as a completion candidate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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