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

View file

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