Send only the prefix to the suggestion server

This commit is contained in:
Eric Freese 2017-01-24 19:58:06 -07:00
parent fba20b042e
commit e33eb570c4
3 changed files with 14 additions and 16 deletions

View File

@ -4,21 +4,18 @@
#--------------------------------------------------------------------#
_zsh_autosuggest_async_fetch_suggestion() {
local strategy_function="_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
local prefix="$(_zsh_autosuggest_escape_command "$1")"
# Send the suggestion command to the pty to fetch a suggestion
zpty -w -n $ZSH_AUTOSUGGEST_PTY_NAME "$strategy_function '$prefix'"$'\0'
# Send the prefix to the pty to fetch a suggestion
zpty -w -n $ZSH_AUTOSUGGEST_PTY_NAME $1 $'\0'
}
# Pty is spawned running this function
_zsh_autosuggest_async_suggestion_server() {
while read -d $'\0' cmd; do
while read -d $'\0' prefix; do
# Kill last bg process
kill -KILL %1 &>/dev/null
# Run suggestion search in the background
print -n -- "$(eval "$cmd")"$'\0' &
echo -n -E "$(_zsh_autosuggest_strategy_default "$prefix")"$'\0' &
done
}

View File

@ -7,5 +7,7 @@
#
_zsh_autosuggest_strategy_default() {
fc -lnrm "$1*" 1 2>/dev/null | head -n 1
setopt localoptions EXTENDED_GLOB
fc -lnrm "${1//(#m)[\\()\[\]|*?~]/\\$MATCH}*" 1 2>/dev/null | head -n 1
}

View File

@ -419,7 +419,9 @@ zle -N _autosuggest-show-suggestion _zsh_autosuggest_show_suggestion
#
_zsh_autosuggest_strategy_default() {
fc -lnrm "$1*" 1 2>/dev/null | head -n 1
setopt localoptions EXTENDED_GLOB
fc -lnrm "${1//(#m)[\\()\[\]|*?~]/\\$MATCH}*" 1 2>/dev/null | head -n 1
}
#--------------------------------------------------------------------#
@ -479,21 +481,18 @@ _zsh_autosuggest_strategy_match_prev_cmd() {
#--------------------------------------------------------------------#
_zsh_autosuggest_async_fetch_suggestion() {
local strategy_function="_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
local prefix="$(_zsh_autosuggest_escape_command "$1")"
# Send the suggestion command to the pty to fetch a suggestion
zpty -w -n $ZSH_AUTOSUGGEST_PTY_NAME "$strategy_function '$prefix'"$'\0'
# Send the prefix to the pty to fetch a suggestion
zpty -w -n $ZSH_AUTOSUGGEST_PTY_NAME $1 $'\0'
}
# Pty is spawned running this function
_zsh_autosuggest_async_suggestion_server() {
while read -d $'\0' cmd; do
while read -d $'\0' prefix; do
# Kill last bg process
kill -KILL %1 &>/dev/null
# Run suggestion search in the background
print -n -- "$(eval "$cmd")"$'\0' &
echo -n -E "$(_zsh_autosuggest_strategy_default "$prefix")"$'\0' &
done
}