Simplify escaping of pattern and fix match_prev_cmd strategy
Maybe this is also a fix for #247, #248 and #258. Supersedes #267. Testcase: Using match_prev_cmd strategy and with these lines in history: echo '1^' echo '2^' echo '1^' type: echo (unexpected suggestion echo '1^' instead of echo '2^') echo '1^1 (wrong suggestion echo '1^1echo '1^') echo '1^# (error "bad math expression")
This commit is contained in:
@@ -7,19 +7,9 @@
|
||||
#
|
||||
|
||||
_zsh_autosuggest_strategy_default() {
|
||||
# Reset options to defaults and enable LOCAL_OPTIONS
|
||||
emulate -L zsh
|
||||
|
||||
# Enable globbing flags so that we can use (#m)
|
||||
setopt EXTENDED_GLOB
|
||||
|
||||
# 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
|
||||
local prefix="${1//(#m)[\\*?[\]<>()|^~#]/\\$MATCH}"
|
||||
local prefix="$1"
|
||||
|
||||
# Get the history items that match
|
||||
# - (r) subscript flag makes the pattern match on values
|
||||
suggestion="${history[(r)$prefix*]}"
|
||||
|
||||
suggestion="${history[(r)${(b)prefix}*]}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user