mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-08 15:32:31 +01:00
A new suggestion strategy 'match_prev_cmd' is available. This is a bit more context aware variaton on the default strategy. The suggestion will be: - The newest history entry that matches the current prefix, AND - Whose preceding history entry also matches the previously executed command. See src/strategies/match_prev_cmd.zsh for an example.
26 lines
833 B
Bash
26 lines
833 B
Bash
|
|
#--------------------------------------------------------------------#
|
|
# Suggestion #
|
|
#--------------------------------------------------------------------#
|
|
|
|
# Delegate to the selected strategy to determine a suggestion
|
|
_zsh_autosuggest_suggestion() {
|
|
local prefix="$1"
|
|
local strategy_function="_zsh_autosuggest_strategy_$ZSH_AUTOSUGGEST_STRATEGY"
|
|
|
|
if [ -n "$functions[$strategy_function]" ]; then
|
|
echo -E "$($strategy_function "$prefix")"
|
|
fi
|
|
}
|
|
|
|
_zsh_autosuggest_escape_command_prefix() {
|
|
setopt localoptions EXTENDED_GLOB
|
|
|
|
# Escape special chars in the string (requires EXTENDED_GLOB)
|
|
echo -E "${1//(#m)[\\()\[\]|*?]/\\$MATCH}"
|
|
}
|
|
|
|
# Get the previously executed command (hookable for testing)
|
|
_zsh_autosuggest_prev_command() {
|
|
echo -E "${history[$((HISTCMD-1))]}"
|
|
}
|