From e33eb570c461e4f0c97d7ce1f2c33a15f2a200b7 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 24 Jan 2017 19:58:06 -0700 Subject: [PATCH] Send only the prefix to the suggestion server --- src/async.zsh | 11 ++++------- src/strategies/default.zsh | 4 +++- zsh-autosuggestions.zsh | 15 +++++++-------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/async.zsh b/src/async.zsh index 91c3587..2e23fb6 100644 --- a/src/async.zsh +++ b/src/async.zsh @@ -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 } diff --git a/src/strategies/default.zsh b/src/strategies/default.zsh index 29333f5..a242ee0 100644 --- a/src/strategies/default.zsh +++ b/src/strategies/default.zsh @@ -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 } diff --git a/zsh-autosuggestions.zsh b/zsh-autosuggestions.zsh index f99953b..f85aac6 100644 --- a/zsh-autosuggestions.zsh +++ b/zsh-autosuggestions.zsh @@ -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 }