mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
WIP implementing a historywords suggestion strategy
This commit is contained in:
parent
c80605595c
commit
36dae44064
2 changed files with 56 additions and 0 deletions
28
src/strategies/historywords.zsh
Normal file
28
src/strategies/historywords.zsh
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
#--------------------------------------------------------------------#
|
||||
# History Words Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history word that matches the given
|
||||
# prefix.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_historywords() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m)
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
local last_word="${${=1}[-1]}"
|
||||
|
||||
# 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="${last_word//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the first history word that matches. Concatenate it together with the
|
||||
# prefix to form the full suggestion.
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
typeset -g suggestion="${1:0:-$#last_word}${historywords[(r)${prefix}?*]}"
|
||||
}
|
|
@ -611,6 +611,34 @@ _zsh_autosuggest_strategy_completion() {
|
|||
}
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# History Words Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
# Suggests the most recent history word that matches the given
|
||||
# prefix.
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_historywords() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m)
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
local last_word="${${=1}[-1]}"
|
||||
|
||||
# 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="${last_word//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
|
||||
# Get the first history word that matches. Concatenate it together with the
|
||||
# prefix to form the full suggestion.
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
typeset -g suggestion="${1:0:-$#last_word}${historywords[(r)${prefix}?*]}"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# History Suggestion Strategy #
|
||||
#--------------------------------------------------------------------#
|
||||
|
|
Loading…
Reference in a new issue