mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
wip playing with different strategies when for different patterns
This commit is contained in:
parent
146020d9b2
commit
b27277e7ff
3 changed files with 78 additions and 22 deletions
|
@ -17,7 +17,10 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|||
# Will try each strategy in order until a suggestion is returned
|
||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(
|
||||
'cd *:completion'
|
||||
'*:history,completion'
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that clear the suggestion
|
||||
|
|
|
@ -8,13 +8,35 @@
|
|||
|
||||
_zsh_autosuggest_fetch_suggestion() {
|
||||
typeset -g suggestion
|
||||
local -a strategies
|
||||
local strategy
|
||||
local -a strategy_specs spec_parts strategies
|
||||
local strategy_spec strategy prefix
|
||||
|
||||
# Ensure we are working with an array
|
||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
||||
strategy_specs=(${ZSH_AUTOSUGGEST_STRATEGY})
|
||||
|
||||
echo "fetching.." >> debug.log
|
||||
|
||||
for strategy_spec in $strategy_specs; do
|
||||
echo "trying spec: '$strategy_spec'" >> debug.log
|
||||
spec_parts=(${(s/:/)strategy_spec})
|
||||
prefix="${spec_parts[1]}"
|
||||
|
||||
echo "checking prefix: $prefix" >> debug.log
|
||||
echo " spec parts: $spec_parts" >> debug.log
|
||||
|
||||
if [[ "$1" != ${~prefix} ]]; then
|
||||
echo " '$1' didn't match prefix: '$prefix'" >> debug.log
|
||||
continue;
|
||||
fi
|
||||
|
||||
strategies=(${(s/,/)${spec_parts[2]}})
|
||||
|
||||
echo " trying strategies: $strategies" >> debug.log
|
||||
|
||||
for strategy in $strategies; do
|
||||
|
||||
echo " trying strategy $strategy" >> debug.log
|
||||
|
||||
# Try to get a suggestion from this strategy
|
||||
_zsh_autosuggest_strategy_$strategy "$1"
|
||||
|
||||
|
@ -22,6 +44,9 @@ _zsh_autosuggest_fetch_suggestion() {
|
|||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||
|
||||
# Break once we've found a valid suggestion
|
||||
[[ -n "$suggestion" ]] && break
|
||||
[[ -n "$suggestion" ]] && return
|
||||
|
||||
echo " didn't get suggestion" >> debug.log
|
||||
done
|
||||
done
|
||||
}
|
||||
|
|
|
@ -43,7 +43,10 @@ typeset -g ZSH_AUTOSUGGEST_ORIGINAL_WIDGET_PREFIX=autosuggest-orig-
|
|||
# Will try each strategy in order until a suggestion is returned
|
||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(
|
||||
'cd *:completion'
|
||||
'*:history,completion'
|
||||
)
|
||||
}
|
||||
|
||||
# Widgets that clear the suggestion
|
||||
|
@ -708,13 +711,35 @@ _zsh_autosuggest_strategy_match_prev_cmd() {
|
|||
|
||||
_zsh_autosuggest_fetch_suggestion() {
|
||||
typeset -g suggestion
|
||||
local -a strategies
|
||||
local strategy
|
||||
local -a strategy_specs spec_parts strategies
|
||||
local strategy_spec strategy prefix
|
||||
|
||||
# Ensure we are working with an array
|
||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
||||
strategy_specs=(${ZSH_AUTOSUGGEST_STRATEGY})
|
||||
|
||||
echo "fetching.." >> debug.log
|
||||
|
||||
for strategy_spec in $strategy_specs; do
|
||||
echo "trying spec: '$strategy_spec'" >> debug.log
|
||||
spec_parts=(${(s/:/)strategy_spec})
|
||||
prefix="${spec_parts[1]}"
|
||||
|
||||
echo "checking prefix: $prefix" >> debug.log
|
||||
echo " spec parts: $spec_parts" >> debug.log
|
||||
|
||||
if [[ "$1" != ${~prefix} ]]; then
|
||||
echo " '$1' didn't match prefix: '$prefix'" >> debug.log
|
||||
continue;
|
||||
fi
|
||||
|
||||
strategies=(${(s/,/)${spec_parts[2]}})
|
||||
|
||||
echo " trying strategies: $strategies" >> debug.log
|
||||
|
||||
for strategy in $strategies; do
|
||||
|
||||
echo " trying strategy $strategy" >> debug.log
|
||||
|
||||
# Try to get a suggestion from this strategy
|
||||
_zsh_autosuggest_strategy_$strategy "$1"
|
||||
|
||||
|
@ -722,7 +747,10 @@ _zsh_autosuggest_fetch_suggestion() {
|
|||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||
|
||||
# Break once we've found a valid suggestion
|
||||
[[ -n "$suggestion" ]] && break
|
||||
[[ -n "$suggestion" ]] && return
|
||||
|
||||
echo " didn't get suggestion" >> debug.log
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue