Refactor to remove prev cmd function and simplify escaping

This commit is contained in:
Eric Freese 2016-04-25 14:19:26 -06:00
commit 011d8bdfd1
6 changed files with 20 additions and 48 deletions

View file

@ -345,11 +345,11 @@ zle -N autosuggest-execute _zsh_autosuggest_widget_execute
# Delegate to the selected strategy to determine a suggestion
_zsh_autosuggest_suggestion() {
local prefix="$1"
local escaped_prefix="$(_zsh_autosuggest_escape_command "$1")"
local strategy_function="_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
if [ -n "$functions[$strategy_function]" ]; then
echo -E "$($strategy_function "$prefix")"
echo -E "$($strategy_function "$escaped_prefix")"
fi
}
@ -360,11 +360,6 @@ _zsh_autosuggest_escape_command() {
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
}
# Get the previously executed command
_zsh_autosuggest_prev_command() {
echo -E "${history[$((HISTCMD-1))]}"
}
#--------------------------------------------------------------------#
# Default Suggestion Strategy #
#--------------------------------------------------------------------#
@ -373,7 +368,7 @@ _zsh_autosuggest_prev_command() {
#
_zsh_autosuggest_strategy_default() {
local prefix="$(_zsh_autosuggest_escape_command "$1")"
local prefix="$1"
# Get the keys of the history items that match
local -a histkeys
@ -402,7 +397,7 @@ _zsh_autosuggest_strategy_default() {
#
_zsh_autosuggest_strategy_match_prev_cmd() {
local prefix="$(_zsh_autosuggest_escape_command "$1")"
local prefix="$1"
# Get all history event numbers that correspond to history
# entries that match pattern $prefix*
@ -413,8 +408,7 @@ _zsh_autosuggest_strategy_match_prev_cmd() {
local histkey="${history_match_keys[1]}"
# Get the previously executed command
local prev_cmd="$(_zsh_autosuggest_prev_command)"
prev_cmd="$(_zsh_autosuggest_escape_command "$prev_cmd")"
local prev_cmd="$(_zsh_autosuggest_escape_command "${history[$((HISTCMD-1))]}")"
# Iterate up to the first 200 history event numbers that match $prefix
for key in "${(@)history_match_keys[1,200]}"; do