mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-03-24 11:41:25 +01:00
30 lines
850 B
Bash
30 lines
850 B
Bash
|
|
#--------------------------------------------------------------------#
|
|
# Fetch Suggestion #
|
|
#--------------------------------------------------------------------#
|
|
# Loops through all specified strategies and returns a suggestion
|
|
# from the first strategy to provide one.
|
|
#
|
|
|
|
_zsh_autosuggest_fetch_suggestion() {
|
|
typeset -g suggestion
|
|
local -a strategies
|
|
local strategy
|
|
|
|
# Ensure we are working with an array
|
|
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
|
|
|
for strategy in $strategies; do
|
|
# Try to get a suggestion from this strategy
|
|
_zsh_autosuggest_strategy_$strategy "$1"
|
|
|
|
# Ensure the suggestion matches the prefix
|
|
if [[ "$suggestion" != "$1"* ]]; then
|
|
unset suggestion
|
|
unset new_buffer
|
|
fi
|
|
|
|
# Break once we've found a valid suggestion
|
|
[[ -n "$suggestion" ]] && break
|
|
done
|
|
}
|