mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-25 10:01:05 +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
|
# Will try each strategy in order until a suggestion is returned
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
ZSH_AUTOSUGGEST_STRATEGY=(
|
||||||
|
'cd *:completion'
|
||||||
|
'*:history,completion'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Widgets that clear the suggestion
|
# Widgets that clear the suggestion
|
||||||
|
|
|
@ -8,20 +8,45 @@
|
||||||
|
|
||||||
_zsh_autosuggest_fetch_suggestion() {
|
_zsh_autosuggest_fetch_suggestion() {
|
||||||
typeset -g suggestion
|
typeset -g suggestion
|
||||||
local -a strategies
|
local -a strategy_specs spec_parts strategies
|
||||||
local strategy
|
local strategy_spec strategy prefix
|
||||||
|
|
||||||
# Ensure we are working with an array
|
# Ensure we are working with an array
|
||||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
strategy_specs=(${ZSH_AUTOSUGGEST_STRATEGY})
|
||||||
|
|
||||||
for strategy in $strategies; do
|
echo "fetching.." >> debug.log
|
||||||
# Try to get a suggestion from this strategy
|
|
||||||
_zsh_autosuggest_strategy_$strategy "$1"
|
|
||||||
|
|
||||||
# Ensure the suggestion matches the prefix
|
for strategy_spec in $strategy_specs; do
|
||||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
echo "trying spec: '$strategy_spec'" >> debug.log
|
||||||
|
spec_parts=(${(s/:/)strategy_spec})
|
||||||
|
prefix="${spec_parts[1]}"
|
||||||
|
|
||||||
# Break once we've found a valid suggestion
|
echo "checking prefix: $prefix" >> debug.log
|
||||||
[[ -n "$suggestion" ]] && break
|
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"
|
||||||
|
|
||||||
|
# Ensure the suggestion matches the prefix
|
||||||
|
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||||
|
|
||||||
|
# Break once we've found a valid suggestion
|
||||||
|
[[ -n "$suggestion" ]] && return
|
||||||
|
|
||||||
|
echo " didn't get suggestion" >> debug.log
|
||||||
|
done
|
||||||
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
|
# Will try each strategy in order until a suggestion is returned
|
||||||
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
(( ! ${+ZSH_AUTOSUGGEST_STRATEGY} )) && {
|
||||||
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
typeset -ga ZSH_AUTOSUGGEST_STRATEGY
|
||||||
ZSH_AUTOSUGGEST_STRATEGY=(history)
|
ZSH_AUTOSUGGEST_STRATEGY=(
|
||||||
|
'cd *:completion'
|
||||||
|
'*:history,completion'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Widgets that clear the suggestion
|
# Widgets that clear the suggestion
|
||||||
|
@ -708,21 +711,46 @@ _zsh_autosuggest_strategy_match_prev_cmd() {
|
||||||
|
|
||||||
_zsh_autosuggest_fetch_suggestion() {
|
_zsh_autosuggest_fetch_suggestion() {
|
||||||
typeset -g suggestion
|
typeset -g suggestion
|
||||||
local -a strategies
|
local -a strategy_specs spec_parts strategies
|
||||||
local strategy
|
local strategy_spec strategy prefix
|
||||||
|
|
||||||
# Ensure we are working with an array
|
# Ensure we are working with an array
|
||||||
strategies=(${=ZSH_AUTOSUGGEST_STRATEGY})
|
strategy_specs=(${ZSH_AUTOSUGGEST_STRATEGY})
|
||||||
|
|
||||||
for strategy in $strategies; do
|
echo "fetching.." >> debug.log
|
||||||
# Try to get a suggestion from this strategy
|
|
||||||
_zsh_autosuggest_strategy_$strategy "$1"
|
|
||||||
|
|
||||||
# Ensure the suggestion matches the prefix
|
for strategy_spec in $strategy_specs; do
|
||||||
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
echo "trying spec: '$strategy_spec'" >> debug.log
|
||||||
|
spec_parts=(${(s/:/)strategy_spec})
|
||||||
|
prefix="${spec_parts[1]}"
|
||||||
|
|
||||||
# Break once we've found a valid suggestion
|
echo "checking prefix: $prefix" >> debug.log
|
||||||
[[ -n "$suggestion" ]] && break
|
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"
|
||||||
|
|
||||||
|
# Ensure the suggestion matches the prefix
|
||||||
|
[[ "$suggestion" != "$1"* ]] && unset suggestion
|
||||||
|
|
||||||
|
# Break once we've found a valid suggestion
|
||||||
|
[[ -n "$suggestion" ]] && return
|
||||||
|
|
||||||
|
echo " didn't get suggestion" >> debug.log
|
||||||
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue