Add suggestion "strategy" concept with default strategy

This commit is contained in:
Eric Freese
2016-03-01 12:45:55 -07:00
parent 9df362f783
commit 83f78d0760
5 changed files with 51 additions and 16 deletions

View File

@@ -3,16 +3,14 @@
# Suggestion #
#--------------------------------------------------------------------#
# Get a suggestion from history that matches a given prefix
# Delegate to the selected strategy to determine a suggestion
_zsh_autosuggest_suggestion() {
local prefix="$(_zsh_autosuggest_escape_command_prefix "$1")"
local prefix="$1"
local strategy_function="_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
# Get all history items (reversed) that match pattern $prefix*
local history_matches
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
# Echo the first item that matches
echo -E "$history_matches[1]"
if [ -n "$functions[$strategy_function]" ]; then
echo -E "$($strategy_function "$prefix")"
fi
}
_zsh_autosuggest_escape_command_prefix() {