2016-02-06 06:14:08 +08:00
|
|
|
|
2016-02-14 15:29:43 +08:00
|
|
|
#--------------------------------------------------------------------#
|
|
|
|
# Suggestion #
|
|
|
|
#--------------------------------------------------------------------#
|
2016-02-06 06:14:08 +08:00
|
|
|
|
|
|
|
# Get a suggestion from history that matches a given prefix
|
|
|
|
_zsh_autosuggest_suggestion() {
|
|
|
|
setopt localoptions extendedglob
|
|
|
|
|
|
|
|
# Escape the prefix (requires EXTENDED_GLOB)
|
2016-02-17 00:33:26 +08:00
|
|
|
local prefix="${1//(#m)[\][()|\\*?#<>~^]/\\$MATCH}"
|
2016-02-06 06:14:08 +08:00
|
|
|
|
2016-02-17 01:30:34 +08:00
|
|
|
# Get all history items (reversed) that match pattern $prefix*
|
|
|
|
local history_matches
|
|
|
|
history_matches=(${(j:\0:s:\0:)history[(R)$prefix*]})
|
|
|
|
|
|
|
|
# Echo the first item that matches
|
|
|
|
echo "$history_matches[1]"
|
2016-02-06 06:14:08 +08:00
|
|
|
}
|