mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-08 15:32:31 +01:00
Add history cycling widgets
This commit is contained in:
parent
ebaf409002
commit
09b6c1659f
8 changed files with 244 additions and 40 deletions
|
|
@ -2,8 +2,8 @@
|
|||
#--------------------------------------------------------------------#
|
||||
# Default Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history item that matches the given
|
||||
# prefix.
|
||||
# Suggests the history item that matches the given prefix and history
|
||||
# index
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_default() {
|
||||
|
|
@ -13,13 +13,21 @@ _zsh_autosuggest_strategy_default() {
|
|||
# Enable globbing flags so that we can use (#m)
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# Extract the paramenters for this function
|
||||
typeset -g capped_history_index="${1}"
|
||||
local query="${2}"
|
||||
|
||||
# Escape backslashes and all of the glob operators so we can use
|
||||
# this string as a pattern to search the $history associative array.
|
||||
# - (#m) globbing flag enables setting references for match data
|
||||
# TODO: Use (b) flag when we can drop support for zsh older than v5.0.8
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
local prefix="${query//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the history items that match
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
typeset -g suggestion="${history[(r)${prefix}*]}"
|
||||
# - (R) subscript flag makes the pattern match on values
|
||||
# - (k) returns the entry indices instead of values
|
||||
local suggestions=(${(k)history[(R)$prefix*]})
|
||||
|
||||
(( capped_history_index > $#suggestions )) && capped_history_index=${#suggestions}
|
||||
typeset -g suggestion="${history[${suggestions[${capped_history_index}]}]}"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue